freakyleaks Posted July 23, 2008 Posted July 23, 2008 Hi I am having a problem with this insert statement have I written it correctly please thanks in advance. All errors pointed out will be fantastic !!! if (isset($_POST['Add'])){ $hardwareid = mysql_real_escape_string($_POST['hardwareid']); $departmentid = mysql_real_escape_string($_POST['departmentid']); $roomid = mysql_real_escape_string($_POST['roomid']); //insert $equiptmenttype = mysql_real_escape_string($_POST['equiptmenttype']); $serialnumber = mysql_real_escape_string($_POST['serialnumber']); $suppilername = mysql_real_escape_string($_POST['suppilername']); $price = mysql_real_escape_string($_POST['price']); $present = mysql_real_escape_string($_POST['present']); $query5 ="INSERT INTO hardware VALUES('','$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"; mysql_query("INSERT INTO hardware VALUES("",'$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"; }
penfold_99 Posted July 23, 2008 Posted July 23, 2008 Try adding the "." in to the queary then you will construct the string correctly $query5 ="INSERT INTO hardware VALUES('',' . $departmentid .',' .$roomid .',' . $equiptmenttype . ',' . $serialnumber . ',' . $suppilername .',' . $price .',' .$present')";
contink Posted July 23, 2008 Posted July 23, 2008 (edited) $query5 ="INSERT INTO hardware ('dept_id', 'room_id', 'equiptype', ... etc... , 'present') VALUES('','$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"; mysql_query($query5) or die(mysql_error()); That's the bit you're going to be having problems with... I've setup the code as an example as you haven't listed the tables column headers/labels so you need to edit the ('dept_id', 'room_id', 'equiptype', ... etc... , 'present') bit accordingly... It'll also provide you with an error as to why it didn't like it which is good debugging practice. The suggestion re: the dots, etc... isn't necessary as you're using double quotes to enclose the $query5 string.. You would need to if you were using single quotes. Edited July 23, 2008 by contink
dhicks Posted July 23, 2008 Posted July 23, 2008 Hi I am having a problem with this insert statement You'll have to tell us what the problem you are having is. Do you get a PHP syntax error, or an SQL syntax error? Does the data go in to the database, just in the wrong way or a way you weren't expecting? $query5 ="INSERT INTO hardware VALUES('','$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')"; mysql_query("INSERT INTO hardware VALUES("",'$departmentid','$roomid','$equiptmenttype','$serialnumber','$suppilername', '$price', '$present')";[/quote You construct the query string twice? Probably you meant to do something like: $query5 = ... print $query5; # For debugging purposes - does the SQL query string look like you expected? mysql_query($query5); -- David Hicks
srochford Posted July 23, 2008 Posted July 23, 2008 Not sure what you're doing here, but if the data could already exist then this will either end up with duplicate records (bad :-() or just fail. What I always do is try to delete the record based on key field and then do an insert.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now