Page 1 of 1

Updating info to database

Posted: Sat Sep 27, 2003 12:06 pm
by Linkjames
No doubt a case of missing somthing obvious, but this one has me stumped. Code should update a MySql row. But it dosen't (Suprise). Any ideas?

Code: Select all

<html>
<head>
<title>Question update</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<? // First part of script time script ?>
<?PHP include("../includes/exetime1.php"); ?>
<body>
<?PHP
//Connect to MySql
include("../includes/connect.php");
//Select Database
include("../includes/dbselect.php");
// Set ID variable from the GET URL
$answer = $_POST['answer'];
$updatequestion = @mysql_query("UPDATE search SET answer='$answer' answered=1 WHERE id'=$id'");
echo ('Question answered<P>');
?>

<?PHP // Second part of script time script ?>
<?PHP include("../includes/exetime2.php"); ?>
</body>
</html>
Thanks for any help - Linkjames

Posted: Sat Sep 27, 2003 12:16 pm
by wmasterj
I'm pretty sure this should work

Code: Select all

<?php
mysql_query("UPDATE search SET(answer, answered) VALUES($answer, $answered)");
?>
but then maybe that whas for INSERT ... ? try it!.... i hope it helps! :) :wink:

Posted: Sat Sep 27, 2003 12:23 pm
by wmasterj
no....i see the problem.... you forgot a ' , ' between

answer='$answer' AND answered=1

Posted: Sat Sep 27, 2003 12:39 pm
by Linkjames
Thanks for trying, but thats not it. Currently trying

Code: Select all

<html>
<head>
<title>Question update</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<? // First part of script time script ?>
<?PHP include("../includes/exetime1.php"); ?>
<body>
<?PHP
//Connect to MySql
include("../includes/connect.php");
//Select Database
include("../includes/dbselect.php");
// Set ID variable from the GET URL
$answer = $_POST['answer'];
$id = $_POST['id'];
answered = ('1');
$updatequestion = @mysql_query("UPDATE search SET (answer, answered) VALUES ($answer, $answered) WHERE id = '$id'");
echo ('Question answered<P>');
?>

<?PHP // Second part of script time script ?>
<?PHP include("../includes/exetime2.php"); ?>
</body>
</html>
but it still dosen't work...bugger

Posted: Sat Sep 27, 2003 12:45 pm
by JAM

Code: Select all

$updatequestion = @mysql_query("UPDATE search SET answer = '$answer', answered = '$answered' WHERE id = '$id'");

Posted: Sat Sep 27, 2003 12:53 pm
by Linkjames
Again, thank you, but it still won't play...

Posted: Sat Sep 27, 2003 12:59 pm
by Linkjames
*Sigh* I am in fact a muppet. I simply forgot to carry the ID variable from the preceeding page. grrrr

Thanks for your help guys, and sorry to have wasted your time.

Linkjames

Posted: Sat Sep 27, 2003 1:01 pm
by JAM
Yes that would of course help alot. ;)

Posted: Sun Sep 28, 2003 4:23 pm
by wmasterj
hehe...always happy to give a hand - :)

Posted: Mon Sep 29, 2003 3:39 am
by twigletmac
For future reference, removing the SQL statement from the mysql_query() call can make debugging easier, as can mysql_error(), e.g. instead of

Code: Select all

$updatequestion = @mysql_query("UPDATE search SET answer='$answer', answered='$answered' WHERE id = '$id'");
try

Code: Select all

$sql = "UPDATE search SET answer='$answer', answered='$answered' WHERE id = '$id'";
@$updatequestion = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
Mac

Posted: Mon Oct 06, 2003 8:35 am
by webfinearts
<?php
UPDATE search SET answer='{$answer}', answered= '{$answered}'
WHERE .....
is better for you to include the string values between {}, also if you have a numeric value you will have to use just {} without quote, like
answer={$answer}
?>