I am trying to update my table "user" column "img1_name", where the column "blogger_id" equals to $blogger_id and "hotel_id" column equals to $hotel_id.
$sql = "UPDATE user (img1_name) VALUES ('".$img1_name."')
WHERE (blogger_id) = (".$blogger_id.") AND (hotel_id) = ("$hotel_id")";
But it shows error below
Parse error: syntax error, unexpected T_VARIABLE in
/home3/sunangel/public_html/lib/functions/functions.php on line 1593
Can I know how should I edit the line such that it does its function?
You have gone parenthesis crazy and have wrong syntax for your UPDATE statement...
Try this:
$sql = <<<EOT
UPDATE user
SET img1_name = '{$img1_name}'
WHERE blogger_id = {$blogger_id}
AND hotel_id = {$hotel_id}
EOT;
See MySQL documentation for proper UPDATE syntax - http://dev.mysql.com/doc/refman/5.6/en/update.html
Try this :
$sql = "UPDATE user SET img1_name = '".$img1_name."' WHERE blogger_id = ".$blogger_id." AND hotel_id = " . $hotel_id;
Here is SQL UPDATE syntax :
UPDATE your_table_name
SET column_name1 = "your_value",
column_name2 = "another_value"
WHERE your_filter_column = "your_filter_value"
Related
I am trying to update some rows in a table from another row in a different table.
this is the sql I have so far:
UPDATE nymb_posts
JOIN nymb_postmeta
ON nymb_postmeta.post_id = nymb_posts.ID
WHERE nymb_postmeta.meta_key = "_wp_attached_file"
AND nymb_posts.post_type = "attachment"
AND nymb_posts.post_parent = "0"
SET nymb_posts.Guid = nymb_postmeta.meta_value
I just get an "error in your SQL syntax".
If I remove the WHERE clause there is no error. If I make it a SELECT insead of an UPDATE the WHERE clause works.
What is wrong with the WHERE clause?
The set goes before the where:
UPDATE nymb_posts JOIN
nymb_postmeta
ON nymb_postmeta.post_id = nymb_posts.ID
SET nymb_posts.Guid = nymb_postmeta.meta_value
WHERE nymb_postmeta.meta_key = "_wp_attached_file" AND
nymb_posts.post_type = "attachment" AND
nymb_posts.post_parent = "0";
Use set before where clause then it will work
I am using MySQL with ASP.NET/VB. In a table I use GUID instead of int identifiers. All goes as planned until I try to update a specific row, where I get a syntax error in the statement below:
Dim q As String = "UPDATE documents SET date_document = #date_document, document_type = #document_type, sender = #sender, receiver = #receiver, description = #description, document_number = #document_number, pages = #pages, handled_date = current_timestamp, handled_user_id = #handled_user_id, error_code = #error_code) WHERE id = #id"
My GUID parameter:
.Parameters.Add("#id", MySqlDbType.Guid, 16).Value = myguid
And the 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 ') WHERE id = '8873442f-2f0b-4372-ac08-8388220c6eca'' at line 1
Any ideas on what's going on?
You're chasing down the wrong issue. What character does your error syntax begin with? It starts off as ') Where id = ...
You're assuming it's the id. It's not. That works fine. The first character is a closing parenthesis. That's the clue. There is no opening parenthesis. Remove the ) because you don't need it with an update statement.
I have a problem with the following query. It keeps giving me an error 1064 and I don't know what I'm doing wrong.
/*storing in the database */
$query = 'INSERT INTO #__comprofiler SET(`cb_googlex`, `cb_googley`) WHERE `user_id`= \''. $userComplete->id . '\'
VALUES ( \''.$mapCor['latitude'].'\', \''.$mapCor['longitude'].'\')';
$_CB_database->setQuery($query);
$_CB_database->loadResult();
You are trying to do an update here is the correct syntax:
$query = 'UPDATE __comprofiler
SET `cb_googlex` = \''.$mapCor['latitude'].'\',
`cb_googley` = \''.$mapCor['longitude'].'\'
WHERE `user_id`= \''. $userComplete->id . '\';';
String sql = ("insert into registration(pic) values(?) where email='"+Email+"' ");
i get error :error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where email='yyy#ymail.com'' at line 1
You have to use UPDATE query to pass it like
String sql = "UPDATE registration SET pic = ? WHERE email = '" + Email + "'";
Syntax for UPDATE query is
UPDATE table_name SET column_name = value;
Insert query format should be,
"insert into tablename (columnname) values(coulmnvalue)"
OR
"update registration set pic='' where email='"+Email+"'";
Yes. that is impossible.
Either you want:
insert into registration(pic) values(?)
Which will give you a new row;
Or you want an UPDATE:
UPDATE registration SET pic = ?
WHERE email = <EMAILYouWant>
Which will update an existing row where email = the record with the email you want to update the pic column.
$produpd = "UPDATE tblnavpc SET tblnavpc.ChildName = tblnav.NavName " .
"FROM tblnav WHERE tblnavpc.CID = tblnav.NavID";
This is the error I get"
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 'FROM tblnav
WHERE tblnavpc.CID = tblnav.NavID' at
line 1
I know keys aren't named greatly but I just trying to fix this one problem, I didn't name the tables.
You don't have a FROM clause in an update:
UPDATE tblnavpc
INNER JOIN tblnav ON tblnavpc.CID = tblnav.NavID
SET tblnavpc.ChildName = tblnav.NavName
"From" cannot be used with update statements.
Should be
$produpd = "UPDATE tblnavpc SET tblnavpc.ChildName = tblnav.NavName " .
"WHERE tblnavpc.CID = tblnav.NavID";