1

Anyone know what is wrong with the code below and why i get the following error: Error in query: 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 'Update)VALUES ('')' at line 1.

The php code is

<?php
                mysql_connect("localhost" , "" , "") or die (mysql_error());
                mysql_select_db("") or die(mysql_error());
                /* Now we will store the values submitted by form in variable */
                $Update=$_POST['Update'];
                $query = ("INSERT INTO Information (Update) VALUES ('$Update')");
                $result = mysql_query($query) or die("Error in query: ". mysql_error());
                echo "Success";
                mysql_close();
                ?>

and the html is

<form method="POST" action="info.php"> <!-- opens form -->
            <table border="0"> <!-- opens table -->
            Informaiton:<input type="text" name="Update"  />
            <br />
            <input type="Submit" value="Submit" /> <!-- submits details -->

            </table> <!-- closes table -->
            </form> <!-- closes form -->

The table in my database is called Information and the column is called Update.

Thanks!

U007
  • 21
  • 2
  • 2
    You have to quote (back tick) reserved words like `UPDATE`, `SELECT`, etc when used as field names .. read at the [mysql docs](http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html) for more info – dbf Apr 27 '13 at 20:45
  • http://drupal.org/node/141051 – underscore Apr 27 '13 at 20:49
  • Say hello to SQL injections... Please stop using deprecated mysql extension and use prepared statements to avoid SQL injections! – CodeZombie Apr 27 '13 at 20:50

2 Answers2

1

The column's name Update is actually a MySQL keyword (it belongs to the SQL syntax). Try to avoid it, and use something else.

devio
  • 1,147
  • 5
  • 15
  • 41
0

List of SQL reserved words

http://drupal.org/node/141051

775 :UPDATE 

can't use the UPDATE word it is a reserved words

underscore
  • 6,495
  • 6
  • 39
  • 78