error in your SQL syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sketchiie
    New Member
    • Feb 2011
    • 4

    error in your SQL syntax

    Code:
    $naamveld = $_POST['naamveld'];
    $inkoopveld = $_POST['inkoopveld'];
    $aantalveld = $_POST['aantalveld'];
    $verkoopveld = $_POST['verkoopveld'];
    $verkochtveld = $_POST['verkochtveld'];
    $id = $_POST['ID'];
    
    if(isset($_POST['submit'])) 
    { 
    mysql_query("ALTER TABLE `Blad1` (`Naam`, `Inkoop`, `Verkoopprijs`, `Aantal`, `Verkocht`) VALUES ('$naamveld', '$inkoopveld', '$verkoopveld', '$aantalveld', '$verkochtveld') WHERE `id` = '$id'") 
    or die(mysql_error());
    echo "Het is aangepast!";
    }
    I really can't see what I did wrong, the error that shows is:
    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 '(Naam, Inkoop, Verkoopprijs, Aantal, Verkocht) VALUES ('xxx', 'xxx',' at line 1
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Don't you mean to use an INSERT INTO instead of an ALTER TABLE?

    Comment

    • Sketchiie
      New Member
      • Feb 2011
      • 4

      #3
      I mean UPDATE instead of that but that doesn't solve the problem.

      Comment

      • nenana
        New Member
        • Feb 2011
        • 2

        #4
        I dont know you are new at php.If you are;

        alter is being used to add new rows.in your case, update or insert must be the solution.
        First, try to initialize variables and be sure you are getting the names by post.Post will return you the values and values will be assigned the variables.
        Second, if you want to insert values to table:
        Code:
        $sql="INSERT INTO Blad1 (Naam, Inkoop, Verkoopprijs, Aantal, Verkocht) VALUES ('$naamveld', '$inkoopveld', '$verkoopveld', '$aantalveld', '$verkochtveld') WHERE `id` = '$id'";
        $query=mysql_query($sql);
        for update
        UPDATE Blad1 SET
        Naam ='$naamveld',
        Inkoop='$inkoop veld',
        Verkoopprijs='$ verkoopveld',
        Aantal ='$aantalveld',
        Verkocht= '$verkochtveld'
        WHERE id = '$id'";

        Comment

        • Sketchiie
          New Member
          • Feb 2011
          • 4

          #5
          I'm using update, but copied it wrong.
          I didn't knew there's a different code for that, i'm gonna try it asap.

          Thanks in advanced!

          Comment

          Working...