spanner206 Posted October 24, 2013 Share Posted October 24, 2013 hi ive been trying to make these buttons for a while now and its starting to get to the point were im considering lobbing the computer off a bridge and i wouldnt care cause well ile enjoy doing it, but to be fair its a work computer and i might get told off, but yh ive been having problems with this for a couple of days now what im trying to do is put an update record button and a delete record button into my table so you dont have to go into the database to change the records, at the start i had quite a lot of errors and i think ive solved them all and hopefully im down the last few but i really have no clue on how to fix these i have had help over the past few days via this site and its really worked so hopefully this is the last time, aswell as that im very inexperianced in php but snail pace speed getting better. heres the code. <?php $con = mysqli_connect("localhost","root","","lcm"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //updates table. if (isset($_POST["update"])) { $name = mysql_real_escape_string($_POST['name']); $address = mysql_real_escape_string($_POST['address']); $hidden = mysql_real_escape_string($_POST['hidden']); $UpdateQuery = "UPDATE tbl_contactinfo SET Name='$_POST[name]', Address='$_POST[address]' WHERE name='$_POST[hidden]'"; mysqli_query($UpdateQuery, $con); } if (isset($_POST['delete'])) { $name = mysql_real_escape_string($_POST['name']); $address = mysql_real_escape_string($_POST['address']); $hidden = mysql_real_escape_string($_POST['hidden']); $DeleteQuery = "DELETE FROM tbl_contactinfo WHERE Name='$_POST[hidden]'"; mysqli_query($DeleteQuery, $con); } //selects the table. $sql = "Select * from tbl_contactinfo"; if ($result = mysqli_query($con, $sql)) { echo "<table border='1'> <tr> <th>Name</th> <th>Address</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo '<form action="index1.php" method="post">'; echo '<tr>'; echo '<td><input type="text" name="name" value="' . $row['Name'] . '" /></td>'; echo '<td><input type="text" name="address" value="' . $row['Address'] . '" /></td>'; echo '<td><input type="hidden" name="hidden" value="' . $row['ID'] . '" /></td>'; echo '<td><input type="submit" name="update" value="update" /></td>'; echo '<td><input type="submit" name="delete" value="delete" /></td>'; echo '</tr>'; echo '</form>'; } echo "</table>"; } ?> <html> <body> <form action="insert.php" method="post"> Name: <input type="text" name="Name"> Address: <input type="text" name="Address"> <input type="submit"> </form> </body> </html> and the error messages. update error ( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\Index1.php on line 17 Call Stack # Time Memory Function Location 1 0.0000 149320 {main}( ) ..\Index1.php:0 2 0.0000 162976 mysqli_query ( ) ..\Index1.php:17 and the delete error ( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\Index1.php on line 26 Call Stack # Time Memory Function Location 1 0.0000 149448 {main}( ) ..\Index1.php:0 2 0.0000 163136 mysqli_query ( ) ..\Index1.php:26 if anyone knows whats wrong please post as im loosing hair as i speak Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/ Share on other sites More sharing options...
Barand Posted October 24, 2013 Share Posted October 24, 2013 mysqli_query($UpdateQuery, $con); you have the parameters in wrong order - RTFM mysqli_query Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/#findComment-1455184 Share on other sites More sharing options...
spanner206 Posted October 24, 2013 Author Share Posted October 24, 2013 so what order shall i put it in cause that sites got malware on it and tbf dont wana risk it. Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/#findComment-1455187 Share on other sites More sharing options...
mac_gyver Posted October 24, 2013 Share Posted October 24, 2013 lol (about the php.net site) if there are only two parameters and someone told you they were in the wrong order, can't you guess, infer, or deduce what the correct order should be? Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/#findComment-1455189 Share on other sites More sharing options...
spanner206 Posted October 24, 2013 Author Share Posted October 24, 2013 yh i figured it out im not getting the errors anymore but the buttons still dont work?? Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/#findComment-1455190 Share on other sites More sharing options...
Barand Posted October 24, 2013 Share Posted October 24, 2013 Since you are using mysqli, you need to use it consistently $name = mysql_real_escape_string($_POST['name']);$address = mysql_real_escape_string($_POST['address']);$hidden = mysql_real_escape_string($_POST['hidden']); Note the mysqli versions also need the $con parameter (in the first position) Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/#findComment-1455197 Share on other sites More sharing options...
Solution Ch0cu3r Posted October 24, 2013 Solution Share Posted October 24, 2013 Also you're trying to update/delete records where Name=$_POST[hidden]. The form field named hidden contains the records ID value echo '<td><input type="hidden" name="hidden" value="' . $row['ID'] . '" /></td>'; The queries need to update/delete records where the ID column equals to $_POST[hidden]. <?php $con = mysqli_connect("localhost","root","","lcm"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //updates table. if (isset($_POST["update"])) { $name = mysqli_real_escape_string($con, $_POST['name']); $address = mysqli_real_escape_string($con, $_POST['address']); $hidden = mysqli_real_escape_string($con, $_POST['hidden']); $UpdateQuery = "UPDATE tbl_contactinfo SET Name='$name', Address='$address' WHERE ID='$hidden'"; mysqli_query($con, $UpdateQuery); } if (isset($_POST['delete'])) { $hidden = mysqli_real_escape_string($con, $_POST['hidden']); $DeleteQuery = "DELETE FROM tbl_contactinfo WHERE ID='$hidden'"; mysqli_query($con, $DeleteQuery); } //selects the table. $sql = "Select * from tbl_contactinfo"; if ($result = mysqli_query($con, $sql)) { echo "<table border='1'> <tr> <th>Name</th> <th>Address</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo '<form action="index1.php" method="post">'; echo '<tr>'; echo '<td><input type="text" name="name" value="' . $row['Name'] . '" /></td>'; echo '<td><input type="text" name="address" value="' . $row['Address'] . '" /></td>'; echo '<td><input type="hidden" name="hidden" value="' . $row['ID'] . '" /></td>'; echo '<td><input type="submit" name="update" value="update" /></td>'; echo '<td><input type="submit" name="delete" value="delete" /></td>'; echo '</tr>'; echo '</form>'; } echo "</table>"; } ?> <html> <body> <form action="insert.php" method="post"> Name: <input type="text" name="Name"> Address: <input type="text" name="Address"> <input type="submit" name="submit"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/#findComment-1455199 Share on other sites More sharing options...
spanner206 Posted October 24, 2013 Author Share Posted October 24, 2013 Ch0cu3r m8 i love u too much right no cheers m8 and thanks to everyone else who was helping Quote Link to comment https://forums.phpfreaks.com/topic/283229-delete-and-update-button-problems/#findComment-1455202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.