PHP Tutorials
Update records
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit</title>
</head>
<body>
<p>Edit MyQuotes</p>
<div>
<?php
include("my_database_connection.php");
$quote_id = $_GET['quote_id'];
$my_query = "SELECT * FROM my_quotes WHERE quote_id='$quote_id' ";
$my_record_set = mysql_query($my_query);
$my_row_var = mysql_fetch_array($my_record_set);
extract($my_row_var);
// stripslashes (PHP 4 and PHP 5) returns a string with backslashes stripped off
// \' becomes ' and double backslashes \\ are made into a single backslash \
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$quote = stripslashes($quote);
$subject = stripslashes($subject);
// close the connection
mysql_close();
?>
</div>
<div>
<form id="myFormName" name="myFormName" action="updated.php" method="post">
first_name:
<input id="first_name" name="first_name" type="text" value="<?php echo $first_name ?>" /><br />
last_name:
<input id="last_name" name="last_name" type="text" value="<?php echo $last_name ?>" /><br /><br />
<!-- Notice the difference between text fields above and this text area -->
quote:
<textarea name="quote" id="quote" cols="65" rows="10"><?php echo $quote ?></textarea><br />
subject:
<input id="subject" name="subject" type="text" value="<?php echo $subject ?>" /><br />
<input type="submit" value="submit" /><input type="hidden" name="quote_id" value="<?php echo $quote_id ?>">
</form>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edited</title>
</head>
<body>
<p>Modify</p>
<?php
include("my_database_connection.php");
$quote_id = $_POST['quote_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$quote = $_POST['quote'];
$subject = $_POST['subject'];
$my_query = "UPDATE my_quotes SET quote_id = '$quote_id', first_name = '$first_name', last_name = '$last_name', quote = '$quote', subject = '$subject' WHERE quote_id='$quote_id' ";
$my_record_set_update = mysql_query($my_query);
if ($my_record_set_update)
{
echo "<h5>The record set has been updated!</h5>";
}
mysql_close();
?>
</body>
</html>