Page 1 of 1
[SOLVED] Update syntax error
Posted: Tue Feb 10, 2004 3:06 pm
by Linkjames
Obviously somthing simple, but can't figure it out
Code: Select all
$update = mysql_query("UPDATE questions SET (asked)VALUES ($asked) WHERE (id = '$id')") or die("Invalid query: " . mysql_error());
returns
Code: Select all
Invalid query: You have an error in your SQL syntax near '(asked) (2) WHERE (id = '18')' at line 1
And I have been playing wih it for an hour with no luck. All the variables are set
Any ideas?
Cheers - LinkJames
Posted: Tue Feb 10, 2004 3:08 pm
by Linkjames
Heres all the code on the page just in case
Code: Select all
<LINK REL=StyleSheet HREF="style/style.css" TYPE="text/css">
<p class="normal">
Question data will show here
</p>
<p class="normal">
<?php
//Set the asked question into a variable
$question = $_GET['question'];
//Get config variables
include "config.php";
//Set connection to database
mysql_connect("$databaseurl","$uname","$pword") or die("Could not connect");
//Select the_answer database
mysql_select_db("theanswer_theanswer") or die("Could not select");
//Create query to check for the qustion
$result = mysql_query("SELECT * FROM questions where question LIKE '$question'") or die("Invalid query: " . mysql_error());
//Run the query and check if there are results
if(mysql_num_rows($result) == 1)
{
$found = "1";
}
else
{
$found = "0";
}
//If results found
if($found == 1)
{
//Check if question has been answered
if($vars['answered'] == 1){
//Create an array of the MySql result
$vars = mysql_fetch_array($result);
//display question
echo $vars['question'];
//display answer
echo $vars['answer'];
}
//Check if question is unanswered
if($vars['answered'] == 0)
{
//Create an array of the MySql result
$vars = mysql_fetch_array($result);
Print "This question has been asked ";
echo $vars['asked'];
Print " times, but has not yet been answered.";
$asked = ($vars['asked'] + 1);
$id = $vars['id'];
$update = mysql_query("UPDATE questions SET (asked) VALUES ($asked) WHERE (id = '$id')") or die("Invalid query: " . mysql_error());
}
}
//If no results found
if($found == 0)
{
$question = $_GET['question'];
//Add the question to the database
$insert = mysql_query("INSERT INTO questions (question, answer, asked) VALUES ('$question','',1)") or die("Invalid query: " . mysql_error());
//Give message saying the question was not found and added
?>
You asked -<br>
<?php
echo $question;
?>
<br>
This is the first time this question has been asked. It has been added to our database
of unanswered questions and will be answered as soon as possible
<?php
}
?>
</p>
Posted: Tue Feb 10, 2004 3:44 pm
by markl999
The syntax is ...
UPDATE foo SET this='$that', something='$whatever' WHERE someid=$someval;
Posted: Tue Feb 10, 2004 4:12 pm
by Linkjames
Thats got it. Thanks very much.
LinkJames