<?phprequire_once('db.php');if(($_REQUEST['action'] != 'update') && ($_REQUEST['id'] > 0)) { # id to edit $editid = $_REQUEST['id']; # grab info $query = "SELECT contact_name,business_name FROM contact WHERE id='".mysql_real_escape_string($editid)."'"; $result = mysql_query($query); if((!$result) || (@mysql_num_rows($result) < 1)) { die('That ID does no exist'); } else { $row = mysql_fetch_object($result); ?> <form action="<?=$SERVER['PHP_SELF']?>?action=update&id=<?=$editid?>" method="post"> <table border=0 cellpadding=5 cellspacing=2> <tr> <th colspan=3 align=center>Update Contact Information</th></tr> <tr> <td> Business Contact Person:<br /> <input type="text" size="30" name="contact_name" value="<?=$row->contact_name?>"> </td> <td align=left colspan=2> Business Name:<br /> <input type="text" size="40" name="business_name" value="<?=$row->business_name?>"> </td></tr> <tr><td colspan=3 align=center> <input type="submit" value="Update"> </td></tr></table> </form> <?php } } elseif(($_REQUEST['action'] == 'update') && ($_REQUEST['id'] > 0)){ # id to edit $editid = $_REQUEST['id']; // check for errors $err = false; // currently, there is no errors. $errmsg = '<b>Error<b><br>'; // empty error msg. msg with no current errors. // check to see if content field is empty or not. if so, make error. if(empty($_POST['contact_name'])){ $err = true; // there is now an error. $errmsg .= 'Content is a required field and must be filled out.<br>'; // append an error msg to the end of $errmsg } // if there's an error ( $err = true ), let them know and exit. if($err) { echo $errmsg; exit; } if(!$err){ // if no errors, do the foloowing // store the fields into an easier writeable variable. so you dont have to type $_POST[''] to use it everytime. $contact_name = $_POST['contact_name']; $business_name = $_POST['business_name']; //connect to the mysql server //insert the new info into the database $query = "update contact set contact_name='". $contact_name ."', business_name='". $business_name ."' where id = '".mysql_real_escape_string($editid)."'"; $result = mysql_query($query) or die(mysql_error()); echo '<a href="'.$_SERVER['PHP_SELF'].'"> return </a>'; }} // close if action = update brace?>