kunyomi Posted April 4, 2010 Share Posted April 4, 2010 Hey guys, I've just started coding php, for a school project. I'm creating a member login system with functions to add/edit contacts. Currently I'm stuck at updating the contacts. I'm able to pull up data into a form in a page called 'edit.php', but after updating and clicking submit, it just returns a blank page and the SQL database is not updated. This is the code from 'edit.php'. <? include ("dbConfig.php"); require ("check.php"); if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id2 = $_GET["id2"]; $sql = "SELECT * FROM contacts WHERE id2=$id2"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden name="id2" value="<?php echo $myrow["id2"] ?>"> Name:<INPUT TYPE="text" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Email:<INPUT TYPE="text" NAME="email" VALUE="<? echo $myrow["email"] ?>" SIZE=30><br> Who:<INPUT TYPE="text" NAME="age" VALUE="<?php echo $myrow["age"] ?>" SIZE=30><br> Birthday:<INPUT TYPE="text" NAME="birthday" VALUE="<? echo $myrow["birthday"] ?>" SIZE=30><br> Address:<TEXTAREA NAME="address" ROWS=10 COLS=30><? echo $myrow["address"] ?></TEXTAREA><br> Number:<INPUT TYPE="text" NAME="number" VALUE="<? echo $myrow["number"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?> <? if ($_POST["$submit"]) { $id2 = $_POST["id2"]; $name = $_POST["name"]; $email = $_POST["email"]; $age = $_POST["age"]; $birthday = $_POST["birthday"]; $address = $_POST["address"]; $number = $_POST["number"]; $sql = "UPDATE contacts SET name='$name',email='$email',age='$age',birthday='$birthday',address='$address',number='$number' WHERE id2=$id2"; $result = mysql_query($sql); echo "Thank you! Information updated."; } } ?> Please help, truly appreciated. Link to comment https://forums.phpfreaks.com/topic/197521-updating-contacts-info-in-mysql-database-via-php/ Share on other sites More sharing options...
greatstar00 Posted April 4, 2010 Share Posted April 4, 2010 in the update part u got $_POST["$submit"] which $submit is a unset variable, it is blank so, your actually accessing $_POST[], and this is nothing, and of course return nothing Link to comment https://forums.phpfreaks.com/topic/197521-updating-contacts-info-in-mysql-database-via-php/#findComment-1036696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.