Jump to content

If blank then dont Update


Russia

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.