www.webdeveloper.com
Results 1 to 3 of 3

Thread: Update mysql table challenges

  1. #1
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197

    Update mysql table challenges

    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

    PHP Code:
    <? 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';
    }
    ?>

  2. #2
    Join Date
    Oct 2005
    Location
    California
    Posts
    603
    What does it look like when you echo the query? Do the variables display values as expected correctly within the query? This could give you a good hint as to what is going on.

  3. #3
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197
    I figured out my problem, the id was nat carring through correctly

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles