php - UPDATE data in the database -


I want to show selected ID data in the form and edit it and update it in database. I selected the data from the database and put it in the input tag but it does not work. help please!

  & lt; Html & gt; & Lt; Body & gt; By & lt;? $ Db = mysql_connect ("localhost", "root", ""); Mysql_select_db ("db_ncs", $ Database); $ Id = $ _GET ['s_id']; If ($ id) {$ result = mysql_query ("SELECT * FROM tbl_student WHERE s_id = $ id"); $ Line = mysql_fetch_assoc ($ result); }? & Gt; & Lt; Form method = "post" action = "update.php" & gt; Name: & lt; Input type = "text" name = "name" value = "& lt ;? php echo $ row ['s_name'] ;? & gt;" / & Gt; & Lt; Br> Contact: & lt; Input type = "text" name = "contact" value = "& lt ;? php echo $ line ['s_contact'] ;? / & Gt; & Lt; Br> Address: & lt; Input type = "text" name = "address" value = "& lt ;? php echo $ row ['s_address'] ;? & gt;" / & Gt; & Lt; Br> E-mail: & lt; Input type = "text" name = "email" value = "& lt ;? php echo $ row ['s_email'] ;? & gt;" / & Gt; & Lt; Br> & Lt; Input type = "submit" name = "update" value = "update" & gt; & Lt; / Form & gt; By & lt;? If (isset ($ _ POST ['update'])) {$ name = $ _POST ['s_name']; $ Contact = $ _POST ['s_contact']; $ Address = $ _POST ['s_address']; $ Email = $ _POST ['s_email']; $ Sql ​​= "update tbl_student SET (s_name = '$ name', s_contact = '$ contact', s_address = '$ address', s_email = '$ email') WHERE s_id = $ id"; $ Res = mysql_query ($ sql); If ($ res) {echo "update successful!"; } Else {echo "Sorry!"; }}? & Gt; & Lt; / Body & gt; & Lt; / Html & gt;  

You forgot to pass the ID.

Add to this center & lt; Form & gt; tag.

  & lt; Input type = "hidden" name = "s_id" value = "& lt ;? php echo $ id;? & Gt;" / & gt;  

You also need to make your methods consistent. The form submits data through the form method = "get" , but you ask for it through $ _ POST

You also need to create an input name similar to the names by adding or removing either "s_".


Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -