SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert data into an existing row

    How do I write the code to insert data into a specific row which is based on a Session number? I'm trying to do something like this but the WHERE syntax is wrong.

    //get $_SESSION['session'] number (which is the ID number )
    if (isset($_SESSION["session"])){
    $currentSession = $_SESSION['session'];
    echo "Session on eval page " . $currentSession . "<br>";
    }

    //put $_SESSION['session'] number into specified row
    $sql = "INSERT INTO congress(session) VALUES('on') WHERE id ($currentSession)";
    $session = mysql_query($sql)
    or die(mysql_error());

    I have started the row on one page with just the ID number - used it as a Session number and left the rest of the row empty. When the form is filled out on the second page I want to fill the empty fields in the row identified by the Session.

    Thanks

  2. #2
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use update query instead of insert

    PHP Code:
    $sql "update congress set session='on' WHERE id=$currentSession"
    Barbara

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Bristol, England
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to use the UPDATE command, not the INSERT.

    PHP Code:
    mysql_query("UPDATE `congress`
    SET `session` = 'on'
    WHERE `id` = '" 
    mysql_real_escape_string($currentSession) . "'
    LIMIT 1"
    ) or die(mysql_error()); 


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
  •