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'";
Related
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);
?>
I've been trying to make a php form page for the users of my website.
When I open the .php page I got the standard error message :
Could not enter data: 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 emp_id = $emp_id' at line 1
Can anybody help me with the syntax of these commands ???
The Code is here :
<?php
include 'dbc.php';
$emp_id = $_POST['emp_id'];
$emp_name = $_POST['emp_name'];
$emp_address = $_POST['emp_address'];
$emp_salary = $_POST['emp_salary'];
$emp_date = $_POST['join_date'];
$sql = 'INSERT INTO employee SET emp_salary = $emp_salary WHERE emp_id = $emp_id';
mysql_select_db($dbname);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>
The query syntax is wrong. You have to use UPDATE query. As you are enclosing the query in single quote, the PHP variables won't get replaced. So change
$sql = 'UPDATE employee SET emp_salary = $emp_salary WHERE emp_id = $emp_id';
to
$sql = "UPDATE employee SET emp_salary = $emp_salary WHERE emp_id = $emp_id";
or
$sql = 'UPDATE employee SET emp_salary = '.$emp_salary.' WHERE emp_id = '.$emp_id;
Hi again all you good people
I thanks very much for the amount of answers !
The right solution was found and the problem is solved with this statement:
$sql = "UPDATE `employee` SET `emp_salary` = '$emp_salary' WHERE emp_id = '$emp_id'";
Most of you was inded right about the syntax and the choice about UPDATE.
The above statement function very well, but it was a bit hard to find the way.
Thanks again for all your kindness, help and time to answer my help
John Engelsby-Hansen
$sql = 'UPDATE employee SET emp_salary=$emp_salary WHERE emp_id = '.$emp_id;
Insert query should be
$sql = 'INSERT INTO employee SET emp_salary = $emp_salary'; // it is valid without where clause
and there is no meaning for Where clause in Insert Qqery
Actually, if You want to update record then write an update query where we have to set values for column
Like
$sql = 'Update employee SET emp_salary= $emp_salary WHERE emp_id = $emp_id';
Your Update Query is wrong
If its an UPDATE query then it should be
UPDATE employee SET emp_salary = $emp_salary WHERE emp_id = $emp_id
And if you are trying to insert a row then how can you use a WHERE condition?
WHERE condition are used in cases of UPDATE QUERY, NOT INSERT QUery
$select = "SELECT name FROM table_name WHERE location ='".$loc."' ";
$findname = mysql_query($select) or die(mysql_error());
I keep getting this error! I have tried everything!!!
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 location ='Florida'' at line 1
$loc is determined by the following:
<input type="text" name="loc"> in the HTML
$loc = $_POST['loc']; in the PHP
Try this , use mysql_escape_string or mysql_real_escape_string mysql safe string functions
$select = "SELECT `name` FROM `table_name` WHERE `location` ='".mysql_escape_string($loc)."' ";
$findname = mysql_query($select) or die(mysql_error());
$select = "SELECT name FROM table_name WHERE location ='".mysql_real_escape_string($loc)."' ";
$findname = mysql_query($select) or die(mysql_error());
Just check for any single quotes or double quotes in the location variable. That might be a problem.
Use str_replace(find,replace,string) to replace single and double quotes in the string.
Example, when you can contain a double quote in the $loc variable.
$select = "SELECT name FROM table_name WHERE location ='Flo"rida' ";
The query will end at Flo.
use mysql_real_escape_string after WHERE location =
I fixed it. I was using a variable for the table name and was referencing a null value. Thanks for the help!
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());
Right so i have php code to update a SQL table. If i replace $_GET['emailID'] with a number say 1 the database IS updated. But otherwise no update. What seems to be wrong here
Table: emails
Fields: mailbox, emailID
$query = 'UPDATE `emails` SET `mailbox`=\'trash\' WHERE `emailID`='.(int)$_GET['emailID'];
Do like this
$query = "UPDATE `emails` SET `mailbox`='trash' WHERE `emailID`=".intval($_GET['emailID']);
Can you try this,
$query = 'UPDATE `emails` SET `mailbox`=\'trash\' WHERE `emailID`="'.(int)$_GET['emailID'].'" ';
Value of attribut must be selected by single quotes. Try this:
$query = "UPDATE `emails` SET `mailbox` = 'trash' WHERE `emailID` = '" . intval($_GET['emailID']) . "'";
$query = "UPDATE `emails` SET `mailbox`='trash' WHERE `emailID`= ".$_GET['emailID'];
Try this one sure it will work