real_illusions Posted July 29, 2009 Share Posted July 29, 2009 Hi,I have an error when trying to insert form data into a database.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1I've echoed the data out thats been inserted and theres no 'resource id#4' anywhere in the data.Heres the insert statement, but as far as i can see, theres nothing wrong with it. All the fields match up with the table rows in the database, in both name and order. $company = mysql_escape_string($_POST['customer']);$totalhours = mysql_escape_string($_POST['totaltime']);$setamount = mysql_escape_string($_POST['fixedamount']);$jobtitle = mysql_escape_string($_POST['jobtitle']);$workreasons = mysql_escape_string($_POST['workreasons']);$engineer = mysql_escape_string($_POST['engineer']);$requestby = mysql_escape_string($_POST['requestby']);$date = mysql_escape_string($_POST['date']);$workdone = mysql_escape_string($_POST['workdone']);$query = "INSERT INTO workentries (jobtitle, requestby, date, engineer, customer, workdone, workreasons, totaltime, fixedamount) VALUES ('" . addslashes($jobtitle) . "', '" .addslashes($requestby). "', '" .addslashes($date). "', '" .addslashes($engineer). "', '" .addslashes($customer). "', '" .addslashes($workdone). "', '" .addslashes($workreasons). "', '" .addslashes($totaltime). "', '" .addslashes($fixedamount). "')";mysql_query($query) or die(mysql_error()); Why am i getting that error? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 29, 2009 Share Posted July 29, 2009 I assume that $customer, $totaltime, or $fixedamount are resources. Link to comment Share on other sites More sharing options...
real_illusions Posted July 29, 2009 Author Share Posted July 29, 2009 in what way? what are resources?All data there is taken from a form thats filled out by a user. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 29, 2009 Share Posted July 29, 2009 A resource is a database connection, file handle, query result, etc. The variables I mentioned do not appear in the code you posted, only the query. One of them is a resource. Print the query out to find out which one. Link to comment Share on other sites More sharing options...
real_illusions Posted July 29, 2009 Author Share Posted July 29, 2009 I'm still confused. It was a mistake on my part, i didnt change the variable names to match. But yet im still getting the error. I've printed the query out, but all looks fine to me. All values are how they should be and how i entered them in the form..which is all plain text.Thats how it should be: $customer = mysql_escape_string($_POST['customer']);$totaltime = mysql_escape_string($_POST['totaltime']);$fixedamount = mysql_escape_string($_POST['fixedamount']);$jobtitle = mysql_escape_string($_POST['jobtitle']);$workreasons = mysql_escape_string($_POST['workreasons']);$engineer = mysql_escape_string($_POST['engineer']);$requestby = mysql_escape_string($_POST['requestby']);$date = mysql_escape_string($_POST['date']);$workdone = mysql_escape_string($_POST['workdone']);$query = "INSERT INTO workentries (jobtitle, requestby, date, engineer, customer, workdone, workreasons, totaltime, fixedamount) VALUES ('" . addslashes($jobtitle) . "', '" .addslashes($requestby). "', '" .addslashes($date). "', '" .addslashes($engineer). "', '" .addslashes($customer). "', '" .addslashes($workdone). "', '" .addslashes($workreasons). "', '" .addslashes($totaltime). "', '" .addslashes($fixedamount). "')";mysql_query($query) or die(mysql_error()); Link to comment Share on other sites More sharing options...
justsomeguy Posted July 29, 2009 Share Posted July 29, 2009 The error probably isn't from that query then. If you print the query out and don't see "Resource ID#4" in it, then the error must be somewhere else. Link to comment Share on other sites More sharing options...
real_illusions Posted July 30, 2009 Author Share Posted July 30, 2009 Solved it now.Turned out to be a database query that was causing some trouble which was happening after the query posted above. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.