View Full Version : Resolved error in my syntax
TwitterRooms
01-22-2012, 02:21 PM
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 'WHERE id = 4,' at line 1
this is the error i get and this is what im using to get it
mysql_query("UPDATE data SET dischargetemp=$dischargetemp, condenceron=$condenceron, condenceroff=$condenceroff, leaktest=$leaktest, clean=$clean, saftey=$saftey, fan1=$fan1, fan2=$fan2, fan3=$fan3, notes=$notes, WHERE id = $_SESSION[id] ");
any ideas...
there shouldn't be a comma before your WHERE clause.
TwitterRooms
01-23-2012, 06:28 PM
thanks but even with the comma removed same error is there any whey to get more details of what it wrong with the WHERE clause
could you post what the query looks like after php is done (what does mysql actually see)?
TwitterRooms
01-23-2012, 09:56 PM
ok i'm not shore what you mean but i have echo'ed all the $XXX in the query and they all have a value lets make it simple and try this
mysql_query("UPDATE data SET make=$make WHERE entryid=$_SESSION[id]");
ive taken out all the verables till i get the basic code working then i add them back in with this code i get this error
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 '' at line 1
TwitterRooms
01-23-2012, 10:00 PM
This is the whole file
<?php
session_start();
$con = mysql_connect("XXXXXXXX","XXXXXXX","XXXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("XXXXXXXXXX", $con);
echo mysql_error();
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$make = clean($_POST['make']);
$model = clean($_POST['model']);
$serial = clean($_POST['serial']);
$comp1amps1 = clean($_POST['comp1amps1']);
$comp1amps2 = clean($_POST['comp1amps2']);
$comp1amps3 = clean($_POST['comp1amps3']);
$comp2amps1 = clean($_POST['comp2amps1']);
$comp2amps2 = clean($_POST['comp2amps2']);
$comp2amps3 = clean($_POST['comp2amps3']);
$suction = clean($_POST['suction']);
$discharge = clean($_POST['discharge']);
$suctiontemp = clean($_POST['suctiontemp']);
$dischargetemp = clean($_POST['dischargetemp']);
$condenceron = clean($_POST['condenceron']);
$condenceroff = clean($_POST['condenceroff']);
$leaktest = clean($_POST['leaktest']);
$clean = clean($_POST['clean']);
$saftey = clean($_POST['saftey']);
$fan1 = clean($_POST['fan1']);
$fan2 = clean($_POST['fan2']);
$fan3 = clean($_POST['fan3']);
$notes = clean($_POST['notes']);
mysql_query("UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]");
echo mysql_error();
//mysql_query("UPDATE data SET dischargetemp=$dischargetemp, condenceron=$condenceron, condenceroff=$condenceroff, leaktest=$leaktest, clean=$clean, saftey=$saftey, fan1=$fan1, fan2=$fan2, fan3=$fan3, notes=$notes, WHERE id = $_SESSION[id] ");
//echo '<center><h2 style="color:white;">unit logged ID number is ', $_SESSION['id'];
//echo '</h2></center>
//<link href="style.css" rel="stylesheet" type="text/css" />
//<meta http-equiv="refresh" content="5; URL=index.php">
//<span id="countdown" style="position:absolute;bottom:0px;left:5px;color:yellow;font-size:200%">5</span>
// ';
?>
I'd need to see the string PHP outputs as the query. try replacing this:
mysql_query("UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]");
echo mysql_error();with this:
$query = "UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]";
print $query;
mysql_query( $query );
echo mysql_error();and let me know what it prints.
TwitterRooms
01-24-2012, 06:50 AM
UPDATE data SET make=1, model=2 WHERE entryid=23Unknown column 'make' in 'field list'
WHAT A COCK!!!!!! thank you for your help i feel very stupid now
TwitterRooms
01-24-2012, 04:25 PM
ok i still have a problem
$query = "UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]";
print $query;
mysql_query( $query );
echo mysql_error();
works fine BUT when $make is a word it dont work cos it needs to be make='$make'
how do i get round this
$query = "UPDATE data SET make='$make', model='$model' WHERE entryid='$_SESSION[id]'";
You don't have to worry about it that way - in fact, passing everything to MySQL as a string is fine because it prompts MySQL to do its own type conversion.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.