SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    UPDATE wont enter into database

    Hi guys

    Here is my code

    My problem is that it isnt entering the info into the database

    Thanks in advance for your help




    <form action="updated.php">

    <?php


    //connect to your database ** EDIT REQUIRED HERE **
    mysql_connect("localhost","notexper_two","three"); //(host, username, password)

    //specify database ** EDIT REQUIRED HERE **
    mysql_select_db("notexper_one") or die("Unable to select database"); //select which database we're using







    $sql = ("select * from CV where user_id = '". $_SESSION['seeker'] ."'");




    $result = mysql_query ($sql);

    while ($row = mysql_fetch_array($result))
    {



    $field1= $row["name"];

    $field7= $row["surname"];



    }

    ?>




    <table width=80&#37;><tr><td valign=top>
    First Name/td><td> <input type="text" name="name" value="<? echo $field1; ?>"></td></tr>
    <tr><td>Surname/tD><td><input type="text" name="surname" value="<? echo $field7; ?>"></td></tr>
    </table>
    <input type="Submit" value="Update">
    </form>
    and heres updated.php


    <?

    //connect to your database ** EDIT REQUIRED HERE **
    mysql_connect("localhost","notexper_two","three"); //(host, username, password)

    //specify database ** EDIT REQUIRED HERE **
    mysql_select_db("notexper_one") or die("Unable to select database"); //select which database we're using


    $query=("UPDATE CV SET name='$name', surname='$surname' where user_id = '". $_SESSION['seeker'] ."'");





    @mysql_select_db($database) or die( "Unable to select database");
    mysql_query($query);
    echo "Record Updated";
    mysql_close();
    ?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Try changing these 2 lines
    PHP Code:
    <form action="updated.php" method="GET">


    //then in updated.php
    //AND do this to check everything is coming across as it should

    print_r($_GET) ;

    //if that looks OK (ie you see correct values) then go on and try this

    $query=("UPDATE CV SET name='$_GET['name']', surname='$_GET['surname']' where user_id = '"$_SESSION['seeker'] ."'"); 

  3. #3
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok this is what it printed out


    Record UpdatedArray ( [name] => john [surname] => smith)
    but still not updating

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Change your query to

    PHP Code:
    $query=("UPDATE CV SET name='" $_GET['name'] . "', surname='" $_GET['surname'] . "' where user_id = '"$_SESSION['seeker'] ."'"); 
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is strange

    I tried that but didnt work

  6. #6
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Put this line under the line youve just changed

    PHP Code:
    echo "Your SQL statement is - $query"
    Then report back the result
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  7. #7
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here it is

    Your SQL statement is - UPDATE CV SET name='chrisss', surname='campbell' where user_id = ''Record Updated

  8. #8
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You have a problem around the end of the query.
    Your Session Variable doesnt contain a value, going back to your firrst post you are not calling session_start(); which should be at the top of the scripts.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  9. #9
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mandes

    Dont laugh to much

  10. #10
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I never laugh, thats why I wear the bag !!
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  11. #11
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I always thought it was half of a domino?


Bookmarks

Posting Permissions

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