Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy PHP Code: User input not adding/updating to SQL database

    I have searched over 1500 posts over the last 2 weeks and have not found the solution to make my code work. My registration and login forms work correctly but when the user logins to add or edit information the sql database does not update with the users input and the error/updated message does not echo. My users register with name, surname, email and password but once they login they need to add to their personal information and later be able to edit the personal information. But nothing I've tried has worked...please help me I really need to get this right.... my code is as follows:

    PHP Code:
    <?php
    session_start
    (); 
    $toplinks "";
    if (isset(
    $_SESSION['id'])) {
        
    // Put stored session variables into local php variable
        
    $userid $_SESSION['id'];
        
    $username $_SESSION['username'];
        
    $toplinks '<a href="member_account.php?id=' $userid '">Member Account</a> | 
        <a href="view_personal_details.php">View your Personal Details</a> |
        <a href="edit_personal_details.php">Edit your Personal Details</a> |
        <a href="view_your_cv.php">View your CV</a> |
        <a href="edit_your_cv.php">Edit your CV</a> |
            <a href="logout.php">Log Out</a>'
    ;
    } else {
        echo 
    'Please <a href="login.php">log in</a> to access your account';
        exit(); 
    }
    ?>
    <?php
    include_once "connect_to_mysql.php";
    $id $_SESSION['id'];

    if (
    $_POST['username']) {
    $title $row["title"];
    $username $row["username"];
    $surname $row["surname"];
    $identityno $row["identityno"];
    $gender $row["gender"];
    $birthdate strftime("%d %b %Y"strtotime($row["birthdate"]));
    $ethnicity $row["ethnicity"];
    $nationality $row["nationality"];
    $homeaddress $row["homeaddress"];
    $province $row["province"];
    $suburb $row["suburb"];
    $hometele $row["hometele"];
    $celltele $row["celltele"];
    $creditclear $row["creditclear"];
    $criminalrecord $row["criminalrecord"];
    $driverslicense $row["driverslicense"];
    $owntransport $row["owntransport"];
    $medicalconditions $row["medicalconditions"];

    $sql mysql_query("UPDATE cic_candidates SET title='$title', username='$username', surname='$surname', identityno='$identityno', gender='$gender', birthdate='$birthdate', ethnicity='$ethnicity', nationality='$nationality', homeaddress='$homeaddress', province='$province', suburb='$suburb', hometele='$hometele', celltele='$celltele', creditclear='$creditclear', criminalrecord='$criminalrecord', driverslicense='$driverslicense', owntransport='$owntransport', medicalconditions='$medicalconditions' WHERE id='$id'"); 
        echo 
    'Your account info has been updated, you will now see the new info.<br /><br />
    To return to your profile edit area, <a href="edit_personal_details.php">click here</a>'
    ;
    exit();

    ?>
    <?php
    $sql 
    mysql_query("SELECT * FROM cic_candidates WHERE id='$id' LIMIT 1"); 
    while(
    $row mysql_fetch_array($sql)){
    $email $row["email"];
    $title $row["title"];
    $username $row["username"];
    $surname $row["surname"];
    $identityno $row["identityno"];
    $gender $row["gender"];
    $birthdate strftime("%d %b %Y"strtotime($row["birthdate"]));
    $ethnicity $row["ethnicity"];
    $nationality $row["nationality"];
    $email $row["email"];
    $homeaddress $row["homeaddress"];
    $province $row["province"];
    $suburb $row["suburb"];
    $hometele $row["hometele"];
    $celltele $row["celltele"];
    $creditclear $row["creditclear"];
    $criminalrecord $row["criminalrecord"];
    $driverslicense $row["driverslicense"];
    $owntransport $row["owntransport"];
    $medicalconditions $row["medicalconditions"];
    $accounttype $row["accounttype"];    
    }
    ?>
    Last edited by Fou-Lu; 08-31-2013 at 12:33 PM.

  • #2
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think the problem is somewhere in this code:

    PHP Code:
    <?php
    $sql 
    mysql_query("UPDATE cic_candidates SET title='$title', username='$username',     
    surname='$surname', identityno='$identityno', gender='$gender', birthdate='$birthdate',
    ethnicity='$ethnicity', nationality='$nationality', homeaddress='$homeaddress', 
    province='$province', suburb='$suburb', hometele='$hometele', celltele='$celltele', 
    creditclear='$creditclear', criminalrecord='$criminalrecord', driverslicense='$driverslicense', 
    owntransport='$owntransport', medicalconditions='$medicalconditions' WHERE id='$id'"
    ); 
    echo 
    'Your account info has been updated, you will now see the new info.<br /><br />
    To return to your profile edit area, <a href="edit_personal_details.php">click here</a>'
    ;
    exit();

    ?>
    Last edited by Fou-Lu; 08-31-2013 at 12:36 PM.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If its not executing the SQL nor printing the message after it (there is no error handling here, so it should *always* print the message regardless of results), that indicates you are failing the if ($_POST['username']) check (which isn't correct anyway, that should be using isset).
    Post the HTML form.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Tags for this Thread

    Posting Permissions

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