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
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Data not updating in database.

    PHP Code:
    <?php
    include "../../scripts/connect.php";

    //Load users from dataabse
    mysql_select_db($dbname$con);
    $query="SELECT * FROM users";
    $result=mysql_query($query);
    if (!
    $result) { 
        
    $mess "Unable to update details! (User check error!)";
        
    header("Location:../login.php?mess=$mess");
    }
             
    //Check if username and password matchs
    while ($row=mysql_fetch_array($result)) {
        
    $username=$_SESSION['username'];
        
    $password=$_SESSION['password'];
                
        if (
    $uname != $username && $pword != $password) {
            
    $_SESSION['username'] = "NULL";
            
    $_SESSION['password'] = "NULL";
            
    $mess="Login details are incorrect, unable to update information!";
            
    header("Location: ../login.php?mess=$mess");
        }
    }

    //Unset variables for reuse.
    unset($query,$result);

    //Get data from form
    $var1=$_POST['1'];
    $var2=$_POST['2'];
    $var3=$_POST['3'];
    $var4=$_POST['4'];
    $var5=$_POST['5'];
    $var6=$_POST['6'];
    $var7=$_POST['7'];
    $var8=$_POST['8'];

    //Update database with new information
    mysql_select_db($dbname$con);
    $query="UPDATE tablename SET 
            col1="
    .$var1.",
            col2="
    .$var2.",
            col3="
    .$var3.",
            col4="
    .$var4.",
            col5="
    .$var5.",
            col6="
    .$var6.",
            col7="
    .$var7.",
            col8="
    .$var8." WHERE id=".$id;
            
    //Add the data
    $result=mysql_query($query);
    mysql_close($con);


    //Check that the data has been updated
    if (!result) {
        
    $mess "Error updating information!";
        
    header("Location: ../index.php?mess=$mess");
    } else {
        
    $mess "Successfully updated information!";
        
    header("Location: ../index.php?mess=$mess");
    ?>
    Var names and column name have been changed due to client wants topic to be private.

    Question: The data which is put into the form is not updating in the database, although, the correct data is being displayed if I print the form data onto the screen. :S

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    //Add the data
    $result=mysql_query($query);
    I'm tired of saying this in CF . You need to add proper error checks to your query. Change the above to
    //Add the data
    PHP Code:
    $result=mysql_query($query) or die(mysql_error(). '<br>'$query); 
    and check the result.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    martynball (04-03-2010)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Cheers, got it working now.

    Fix:
    PHP Code:
    $query="UPDATE tablename SET 
            col1='$var1',
            col2='$var2'.... 


  •  

    Posting Permissions

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