Very Simple PHP MySQL Update Problem

Discussion in 'PHP' started by scottlpool2003, Apr 30, 2011.

  1. #1
    I don't understand, I'm trying to edit a field in the db. From the form to the db update page I'm echoing out what I want to edit in the db so I'm guessing it's the WHERE clause that's making it not update. Anyway here's the code:

    <?php
    $id=$_POST['id'];
    $image=$_POST['image']; 
    mysql_query("UPDATE 'slider' SET 
    image = '$image'
    WHERE 'id' = '$id' ");
    echo "<font color=green>Success:</font> The slider image was updated in the database!<br><br><font color=red><b>YOU WILL BE REDIRECTED SHORTLY...</font></b><meta http-equiv='REFRESH' content='3;url=slider.php'>";
    ?> 
    <br>
    <?php echo"$id";?><br>
    <?php echo"$image";?>
    PHP:
    As I say, it's echoing out fine.

    Anyone know how to fix this?
     
    scottlpool2003, Apr 30, 2011 IP
  2. MakZF

    MakZF Well-Known Member

    Messages:
    390
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    140
    #2
    I assume you are connected to the DB beforehand.

    The syntax is incorrect, should be:

    mysql_query("UPDATE `slider` SET
    `image` = '$image'
    WHERE `id` = '$id' ");
    
    PHP:
     
    MakZF, Apr 30, 2011 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    Oh you sexy so-and-so thanks!
     
    scottlpool2003, Apr 30, 2011 IP