Jump to content

Resource Id#4 Error In Mysql Insert Statement


real_illusions
 Share

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...