Mamo Posted April 2, 2013 Share Posted April 2, 2013 hi i want to update my database, but it doesn't work..........here is it code <form action="mysql_2.php" method="POST"> Firstname   :   <input type="text" name="first" ><br> Lastname    :   <input type="text" name="last" ><p>      <input type="submit" name="submit" value="Get Data"> <b> If you want to Update any of these record </b><br> <p>First name : <input type="text" name="firstname1" ><br ></p> <p>Last name : <input type="text" name="lastname1" ><br ></p> <p>dob : <input type="text" name="dob1" ><br ></p> <p>Gender : <input type="text" name="gender1" ><br ></p> <p>    <input type="submit" name="sub" value="Update"></p> </form> the php code read the first, last from the first two text box and select there information from the database, and update these information with the information taken from firstname1, lastname1, dob1, gender1. but it doesnot update <?php require("connect.php"); if (isset($_POST['submit'])) { $firstname_form = $_POST['first']; $lastname_form = $_POST['last']; $carry = $_POST['submit']; $select = mysql_query("SELECT * FROM people WHERE firstname='$firstname_form' AND lastname='$lastname_form' ") or die (mysql_error()); while ($data = mysql_fetch_assoc($select)) { echo '<br>'; $id = $data['id']; $firstname = $data['first']; $lastname = $data['last']; $dob = $data['dob']; $gender = $data['gender']; echo " My name is $firstname_form $lastname_form and i was born in $dob and i am $gender <br>"; } if (isset($_POST['sub'])) { $firstname_form_1 = $_POST['firstname1']; $lastname_form_1 = $_POST['lastname1']; $dob_form = $_POST['dob1']; $gender_form = $_POST['gender1']; $firstname_form_2 = $_POST['first']; $lastname_form_2 = $_POST['last']; $query = "UPDATE people SET firstname='$firstname_form_1' , lastname='$lastname_form_1' , dob='$dob_form' , gender='$gender_form' WHERE firstname='$firstname_form_2' AND lastname='$lastname_form_2' "; $holder = mysql_query($query) or die ("Updates Failed"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/ Share on other sites More sharing options...
teynon Posted April 2, 2013 Share Posted April 2, 2013 Change $holder = mysql_query($query) or die ("Updates Failed"); to $holder = mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/#findComment-1422541 Share on other sites More sharing options...
Jessica Posted April 2, 2013 Share Posted April 2, 2013 You really need to give your table a primary key. Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/#findComment-1422545 Share on other sites More sharing options...
Mamo Posted April 2, 2013 Author Share Posted April 2, 2013 Change $holder = mysql_query($query) or die ("Updates Failed"); to $holder = mysql_query($query) or die(mysql_error()); Thank you I did try it, but it is still not working. Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/#findComment-1422550 Share on other sites More sharing options...
Mamo Posted April 2, 2013 Author Share Posted April 2, 2013 You really need to give your table a primary key. i already have a primary key ....it is "id" Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/#findComment-1422551 Share on other sites More sharing options...
teynon Posted April 2, 2013 Share Posted April 2, 2013 Thank you I did try it, but it is still not working. The point of changing that line was so you know what the error message is. What is the error message? See some of the links in Jessica's footer: Debugging Your Code: Debugging your SQL Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/#findComment-1422552 Share on other sites More sharing options...
Jessica Posted April 3, 2013 Share Posted April 3, 2013 Then why are you using a bunch of fields as your where clause instead of the id?? Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/#findComment-1422554 Share on other sites More sharing options...
Mamo Posted April 3, 2013 Author Share Posted April 3, 2013 the problem was solved, thank you all for helping me. Quote Link to comment https://forums.phpfreaks.com/topic/276449-update/#findComment-1422559 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.