how to update a sql table row.

Discussion in 'PHP' started by micromark, Oct 25, 2007.

  1. #1
    Hi all,

    I have a simple problem.

    I am trying to update a field in a table row with new info. I am using this form -

    <form action="updatequote.php" method="post">
    <input type="text" name="Quote" maxlength="300" value="Type quote"><br />
    <input type="submit" value="Submit">
    <form>
    HTML:
    and this php code:

    <?php
    
    include("config.php");
    include("functions.php");
    
    
    ?>
    <?php
    // Insert a row of information into the table "members"
    mysql_query("update members set quote='$quote'
    VALUES('$_POST[quote]')")
    
    or die(mysql_error());
    
    echo "Data Inserted!";
    
    ?>
    PHP:
    Problem is the field does not update?! i get i nice error message - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES('')' at line 2
     
    micromark, Oct 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Oct 25, 2007 IP
  3. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok,

    im now using this -

    <form action="updatequote.php" method="post">
    <input type="text" name="quote" maxlength="300" value="Type quote"><br />
    <input type="submit" value="Submit">
    <form>
    HTML:

    <?php
    $sql="update members set quote='$quote', where username='$ses_username'"
    $updated=true;
    mysql_query($sql);
    
    ?>
    PHP:
    and get this - Parse error: parse error, unexpected T_VARIABLE in /home/p/i/picturest/public_html/updatequote.php on line 10
     
    micromark, Oct 25, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    <?php
    
    mysql_query("
        UPDATE members
        SET
            quote = '" . substr(mysql_real_escape_string($_POST['quote']), 0, 300) . "'
        WHERE
            username = '" . mysql_real_escape_string($ses_username) . "'
    ") OR die(mysql_error());
    
    $updated=true;
    
    ?>
    
    PHP:

    And I repeat, you should really have a look at the page I posted above.
     
    nico_swd, Oct 25, 2007 IP
  5. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5

    THAT WORKS.. wow i will look, what does the real_escape_string do ? soz im very basic a php
     
    micromark, Oct 25, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Just click the link. :( It's ALL explained there.

    And you should also look at what can happen if you don't use it. (Also on the page above)
     
    nico_swd, Oct 25, 2007 IP