Hi
Below is code that is suppose to update a a found record in a table. There are some conditions that need to be tested before the update is completed
if the change in information results in finding a record in the table then send message and exit code
if there is no match then update the record.
When I run the below coed and there is a match it displays the message. If there is no match it displays message "update has been completed". the problem is the information never gets updated.
any ideas why its not updating
<? session_start(); // Start Session?>
<title>code update</title>
<?
include 'db.php';
$child_id = $_REQUEST['id'];
$firstname= $_POST['childfirstname'];
$lastname = $_POST['childlastname'];
$dob = $_POST['childdob'];
$sex = $_POST['childsex'];
// check to make sure update does not create douplicate value
$sql_child_check = mysql_query("SELECT * FROM children WHERE childlastname = '$lastname' AND childfirstname = '$firstname' AND childdob = '$dob'")or die(mysql_error());
$child_check = mysql_num_rows($sql_child_check);
$row = mysql_fetch_assoc($sql_child_check);
$child_id = $row['child_id'];
// if the change resulted in finding the child in database send message and exit code
if(($child_check == 1)){
$msg .= '<div style="width:325px" id= "formmessage">';
$msg .= "The change you made resulted in finding <b>".$firstname. ' '. $lastname. "</b> in the database<br> <br> <a href='deleteChild.php?id=$child_id&user_id=$user_id'>Delete</a> current person and use <a href='addfamilymembers.php'>Add Child</a> to locate person and create link:<br />";
$msg .= '</div>';
include 'getfamily.php';
exit ();
}
/// no no match found make the update to the childs information
if(($child_check == 0)){
mysql_query("UPDATE children SET childfirstname = '$firstname', childlastname = '$lastname', childdob = '$dob' WHERE child_id = '$child_id'")or die(mysql_error());
$msg .='<div style="width:325px" id= "formmessage">';
$msg .= $firstname. ' '. $lastname. " has been updated.";
$msg .= '</div>';
include 'getfamily.php';
}
?>