Getting this error-
Not sure why, I have looked over it several of times.
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 agentclient = 'admin'' at line 1
In this code-
$sql = mysql_query("UPDATE agentclient SET email='$email2', phone='$phone2', Streetaddress='$address2', faxnumber='$faxnumber2', website='$website2', bio='$bio2', WHERE agentclient = '$agentclient2'") or die(mysql_error());
$sql = mysql_query("UPDATE [...] bio='$bio2', WHERE agentclient = '$agentclient2'")[...]
^ this is wrong
The comma before where is wrong, try:
$sql = mysql_query("UPDATE agentclient SET email='$email2', phone='$phone2', Streetaddress='$address2', faxnumber='$faxnumber2', website='$website2', bio='$bio2' WHERE agentclient = '$agentclient2'") or die(mysql_error());
Related
I have a problem with my UPDATE code. It gives me this error:
Update Failed!! You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id ='2'' at line 4
I'm searching online and I cant find any solution to my problem.
THIS IS MY UPDATE CODE:
<?php
include('db.php');
$id = $_GET['id'];
if (isset($_POST['id'])){
$sql = "UPDATE tbl_student SET stud_id ='".$_POST['stud_id']."',
fullname ='".$_POST['fullname']."',
course ='".$_POST['course']."',
WHERE id ='".$_POST['id']."'";
$result = $conn->query($sql) or die ("Update Failed!!" . $conn->error);
header("location: index.php");
}
else {
echo "ERROR" . $conn->error;
header ("location: update.php");
}
?>
You have added , at last after course . Remove it. Change your query to:
$sql = "UPDATE tbl_student SET stud_id ='".$_POST['stud_id']."',
fullname ='".$_POST['fullname']."',
course ='".$_POST['course']."'
WHERE id ='".$_POST['id']."'";
i am trying to figure out the syntax problem in my query
the block of code goes like this:
$updatequery = "update patient_dim set dentist_id = $dentist_id where".
"patient_id = $patient_id";
$queryResult = mysql_query($updatequery,$con);
if(!$queryResul){
trigger_error("insert error" . mysql_error());
}
mysql_close($con);
then the error goes like this:
Notice: inssert errorYou 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" where patient_id = 4'
i suspect incorrect syntax in the $updatequery statement
for further information value of the $patient_id = 1 while the value of the $dentist_id = 4, i have tried all of your approaches still the same error. anyway thanks your helping
Your query needs space after where
$updatequery = "update patient_dim set dentist_id = $dentist_id where patient_id = $patient_id";
$updatequery = "update patient_dim set dentist_id = $dentist_id where".
" patient_id = $patient_id";
you forgot to add space after WHERE clause
After WHERE Clause there must be a blank space before the condition.
Use as follows.
<?php
$updatequery = "update patient_dim set dentist_id = ".$dentist_id ." where patient_id = ".$patient_id;
$queryResult = mysql_query($updatequery);
if(!$queryResult){
die("insert error" . mysql_error());
}
mysql_close($con);
?>
The error I receive: 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 'release=2012-09-02, platforms=Android, link=`play.php?game=G' at line 6
The code:
$sql = "UPDATE
GameInformation
SET
keyIndex=`GameTest`,
name=`Game Test`,
release=`2012-09-02`,
platforms=`Android`,
link=`play.php?game=GameTest`,
icon=`img/thumb_gametest.png`,
thumb=`img/thumb_mini_gametest.png`,
swf=`swf/GameTest.swf`,
height=`500`,
width=`920`
WHERE
keyIndex=`GameTest2`";
$query = mysql_query($sql);
if (!$query) exit (mysql_error());
I've been trying different delimiters (braces, apostrophes, quotes) around my set vars with no avail. Is there a reserved word in here?
Update [Solved], corrected code:
$sql = 'UPDATE
`GameInformation`
SET
`keyIndex`="GameTest",
`name`="Game Test",
`release`="2012-09-02",
`platforms`="Android",
`link`="play.php?game=GameTest",
`icon`="img/thumb_gametest.png",
`thumb`="img/thumb_mini_gametest.png",
`swf`="swf/GameTest.swf",
`height`="500",
`width`="920"
WHERE
`keyIndex`="GameTest2"';
$query = mysql_query($sql);
if (!$query) exit (mysql_error());
You should use ` for table and column names and " or ' for content. RELEASE is a reserved word.
UPDATE
`GameInformation`
SET
`keyIndex`="GameTest",
`name`="Game Test",
`release`="2012-09-02",
`platforms`="Android",
`link`="play.php?game=GameTest",
`icon`="img/thumb_gametest.png",
`thumb`="img/thumb_mini_gametest.png",
`swf`="swf/GameTest.swf",
`height`="500",
`width`="920"
WHERE
`keyIndex`="GameTest2"
release is a reserved word in mysql.
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
code :
mysql_connect('localhost','root','root');
mysql_select_db('share_counter');
$sql_insert = "UPDATE wpshare SET '$social_name'='45' where post_title = '$post_title' ";
mysql_query($sql_insert) or die(mysql_error());
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
''twitter_count'='45' where post_title
= 'test'' at line 1
thanks advance
omit the quotes over $social_name
$sql_insert = "UPDATE wpshare SET $social_name='45' where post_title = '$post_title' ";
quotes around the column names (aka $social_name) should be like this ` not like this '
so $sql_insert = "UPDATE wpshare SET `$social_name`='45' where post_title = '$post_title' ";
and if your column names have no spaces , you can just remove the quotes ...
$sql_insert = "UPDATE `wpshare` SET `$social_name`='45' WHERE `post_title` = '$post_title'";
My code:
$fileid = $_GET['imgid'];
$fileid = (int)$fileid; //id is int type in photos table
require 'database.php';
//get the image sourc name
$q = "SELECT src form photos WHERE id='$fileid'";
$result = $mysqli->query($q) or die(mysqli_error($mysqli));
if ($result)
{
$row = $result->fetch_object();
$filename = $row->src;
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 'photos WHERE id='12'' at line 1
You have FROM misspelled. Try:
$q = "SELECT src FROM photos WHERE id='$fileid'";
In addition, while not related to this syntax error, note that your code appears to be vulnerable to SQL Injection.