Russia Posted November 4, 2009 Share Posted November 4, 2009 How do I do it so when this page gets run by itself it doesn't update the table, since if it does it will just make all the fields blank. <?php require_once ('inc/config.php'); $firstname = mysql_real_escape_string ($_POST['firstname']); $lastname = mysql_real_escape_string ($_POST['lastname']); $middlename= mysql_real_escape_string ($_POST['middlename']); $id = 2; $sql = mysql_query (" UPDATE `testing` SET `FirstName` = '".$firstname."', `LastName` = '".$lastname."', `MiddleName` = '".$middlename."' WHERE `id` = '".$id."' ") OR die (mysql_error()); ?> Instead make it update the table only when the form updates it? Link to comment https://forums.phpfreaks.com/topic/180347-if-blank-then-dont-update/ Share on other sites More sharing options...
abazoskib Posted November 4, 2009 Share Posted November 4, 2009 use if(isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['middlename'])) { //[rest of your code here] } Link to comment https://forums.phpfreaks.com/topic/180347-if-blank-then-dont-update/#findComment-951364 Share on other sites More sharing options...
Russia Posted November 5, 2009 Author Share Posted November 5, 2009 Thanks I used something a little more simple now I have another question... I am trying to do it so the value in the text box is the current value that is in the database so I do not have to retype, and instead edit it or add on to it. <html> <body> <?php if (isset ($_POST['submit'])) // if the form was submitted, display their name { require_once ('inc/config.php'); $firstname = mysql_real_escape_string ($_POST['firstname']); $lastname = mysql_real_escape_string ($_POST['lastname']); $middlename= mysql_real_escape_string ($_POST['middlename']); $id = 2; $sql = mysql_query (" UPDATE `testing` SET `FirstName` = '".$firstname."', `LastName` = '".$lastname."', `MiddleName` = '".$middlename."' WHERE `id` = '".$id."' ") OR die (mysql_error()); echo "hello"; } //form hasent been submitted { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Firstname: <input type="text" value="<?php echo $row['FirstName'];?>" name="firstname" /><br> Lastname: <input type="text" value="<?php echo $row['LastName'];?>" name="lastname" /><br> middlename: <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" /><br> <input type="submit" id="submit" name="submit" value="Submit!"> </form> <?php } ?> </body> </html> Basicly the value isnt showing up. <input type="text" value="<?php echo $row['MiddleName'];?>" name="middlename" /> How do I fix that? Link to comment https://forums.phpfreaks.com/topic/180347-if-blank-then-dont-update/#findComment-951377 Share on other sites More sharing options...
abazoskib Posted November 5, 2009 Share Posted November 5, 2009 You haven't set the variable $row, so it makes sense that it isnt working. Why dont you just echo $_POST[firstname']..etc? Link to comment https://forums.phpfreaks.com/topic/180347-if-blank-then-dont-update/#findComment-951383 Share on other sites More sharing options...
Russia Posted November 5, 2009 Author Share Posted November 5, 2009 Because its before the form get submited. Its kind of like a php news system. Where I dont want to retype the whole news I just want to echo whats currently in it so I can just edit it. Can you help me out with that? Link to comment https://forums.phpfreaks.com/topic/180347-if-blank-then-dont-update/#findComment-951385 Share on other sites More sharing options...
abazoskib Posted November 5, 2009 Share Posted November 5, 2009 Can you post the code where you set $row? Link to comment https://forums.phpfreaks.com/topic/180347-if-blank-then-dont-update/#findComment-951391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.