wazza91 Posted June 17, 2011 Share Posted June 17, 2011 hi im trying to do a insert query but i keep getting the error messeage ? mysql_error() expects parameter 1 to be resource, object given in /Users/garykane/Sites/update2.php on line 6 success in database entry.-1 row inserted? here is my code <?php $con = mysqli_connect("localhost", "root", "") or die ("No connection"); /*connect to server*/ mysqli_select_db($con ,"Declan") or die ("db will not open"); /*connect to database*/ $dno = $_POST["dno"]; $dname = $_POST["dname"]; $location = $_POST["location"]; $query="Update INTO AccountNumber VALUES (" .$dno . ", '" . $dname . "','" . $location . "')"; if(!mysqli_query($con, $query)) echo mysql_error($con); echo "success in database entry."; $numrows = mysqli_affected_rows($con); echo $numrows . " row inserted<br>"; mysqli_close($con); ?> here is the front end texbox code <html> <head> <title>Question 2, Accounts</title> </head> <h1>Enter Details</h1> <body> <form action="update2.php" method="post"> Account Number : <input type="text" name="dno" /><br /> Balance : <input type="text" name="dname" /><br /> Customer Name : <input type="text" name="location" /><br /> <input type="submit" name="submit" value="submit" /> </form> <?php $con = mysqli_connect("localhost", "root", "") or die ("No connection"); /*connect to server*/ mysqli_select_db($con ,"Declan") or die ("db will not open"); /*connect to database*/ ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/239647-insert-query-help/ Share on other sites More sharing options...
Nodral Posted June 17, 2011 Share Posted June 17, 2011 Where do you actually execute the query? you seem to be missing a mysqli_query line Link to comment https://forums.phpfreaks.com/topic/239647-insert-query-help/#findComment-1231046 Share on other sites More sharing options...
mikosiko Posted June 17, 2011 Share Posted June 17, 2011 just for a start ... im trying to do a insert query ??? INSERT is not the same as UPDATE $query="Update INTO AccountNumber VALUES (" .$dno . ", '" . $dname . "','" . $location . "')"; if(!mysqli_query($con, $query)) echo mysql_error($con); Link to comment https://forums.phpfreaks.com/topic/239647-insert-query-help/#findComment-1231048 Share on other sites More sharing options...
facarroll Posted June 17, 2011 Share Posted June 17, 2011 Should that be "' .$dno . '" and not " .$dno . " ? Link to comment https://forums.phpfreaks.com/topic/239647-insert-query-help/#findComment-1231049 Share on other sites More sharing options...
redixx Posted June 17, 2011 Share Posted June 17, 2011 You are using mysql_error when you should be using mysqli_error. mysqli_error($con); Also your query is wrong. Instead of Update INTO you need INSERT INTO. Link to comment https://forums.phpfreaks.com/topic/239647-insert-query-help/#findComment-1231051 Share on other sites More sharing options...
PFMaBiSmAd Posted June 17, 2011 Share Posted June 17, 2011 Edit: too slow on the submit button, see the same information above ^^^ You also need the i on the mysqli_error($con) statement since you are using mysqli for the connection, query, close... Link to comment https://forums.phpfreaks.com/topic/239647-insert-query-help/#findComment-1231052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.