1

Clueless as to why I keep receiving this error:

Could not Update 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 '1='test' WHERE ID='1'' at line 1

Any help is greatly appreciated

    <?php
mysql_connect("localhost", "root", "root") or die("Error connecting to database: ".mysql_error());

mysql_select_db("stratacache") or die(mysql_error());

if(isset($_GET['edit']))
{
    $id = $_GET['edit'];
    $result = mysql_query("SELECT * FROM Test_Test_Wall_Sites");
    $row = mysql_fetch_array($result);
}

if(isset($_POST['newName']) )
{
    $newName = $_POST['newName'];
    $id      = $_POST['id'];
    mysql_query("UPDATE Persons SET 'COL 1'='$newName' WHERE ID='$id'") or die("Could not Update".mysql_error());

    echo "<meta http-equiv='refresh' content='0;url=index.php'>";
}
              ?>
    <form action="edit_in.php" method="POST">
    Name: <input type = "text" name="newName">
    <input type="hidden" name="id" value="<?php echo $row[0]; ?>">
    <input type="submit" value="CHECK IN">
    </form>

3 Answers 3

1

use backticks around the column name:

mysql_query("UPDATE Persons SET `COL 1`='$newName' WHERE ID='$id'") 
Sign up to request clarification or add additional context in comments.

1 Comment

Sneaky back tick! Thanks a million!
1

You don't need to quote column names but in this case you may need to use backticks:

UPDATE Persons 
SET `COL 1` = '$newName' 
    ^     ^
WHERE ID='$id'

Comments

0

Assuming that Col 1 is really the name of a column you have, you should surround it by backticks, and not single-quotes, which denote literals in SQL:

UPDATE Persons SET `COL 1`='$newName' WHERE ID='$id'"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.