[SOLVED] Update syntax error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

[SOLVED] Update syntax error

Post 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
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post 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>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

The syntax is ...
UPDATE foo SET this='$that', something='$whatever' WHERE someid=$someval;
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

Thats got it. Thanks very much.

LinkJames
Post Reply