Im using mysql, when I want to update a column with this query
UPDATE books
SET ISBN = $ISBN
, Title = '$BookTitle'
, PublicationDate = '$PublicationDate'
, Publisher = '$Publisher'
, Edition = $Edition
, Volume = $Volume
, books.Author_AuthorId = $AuthorId
WHERE ISBN = $GETISBN;
with php it works well while all the input are filled in HTML FORM but if one input is empty already or I clear the previous data in HTML Form and Submit the Form it issues 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 'Volume=1, books.Author_AuthorId=3 WHERE ISBN=5456165156' at line 2
What Should I do?
Here is the query which I have echoed
UPDATE `books` SET `ISBN`=5456165156,`Title`='500 Notice About Java',`PublicationDate`='1390-05-25', `Publisher`='Qods Publication',`Edition`=,`Volume`=1, `books`.`Author_AuthorId`=3 WHERE `ISBN`=5456165156
As long as The $Edition is empty Then The Query Changes like this
`Edition`=
Thats why Mysql can not Understand what value should be set to Edition
Related
I am an amateur programmer creating a PHP based online portal which will update values in a MySQL database in relation to a MMO-type game, in which we are using the portal to track a total number of land tiles protected by each user.
I am working on the script which will update the table count for a given type of protected land, upon submission of an HTML form through a $_POST array.
The MySQL table (players) in question has four similar fields (along with other fields):
wild_count
city_count
nether_count
end_count
On the HTML form, the user can select a land type when submitting, and the script attempts to perform a string concatenate to complete the field, then supplies this for the placeholder in the prepared SQL query, as such:
//Set land type string
$landtype = $_POST['landtype'] . '_count';
//Process ADD request
if (!isset($_POST['negative']))
{
$action = 'ADDED'; //This is for a transaction report further down in the code
try
{
$sql = 'UPDATE players SET
`:landtype` = `:landtype` + :tiles WHERE id = :id';
$query = $link->prepare($sql);
$query->bindValue(':landtype', $landtype);
$query->bindValue(':tiles', $_POST['tiles']);
$query->bindValue(':id', $_POST['player']);
$query->execute();
}
catch (PDOException $e)
{
$error = 'Error updating land count: ' . $e->getMessage();
include './includes/error.inc.php';
exit();
}
...more code follows...
When trying to POST my form using the following code, I get the following error:
Error updating land count: SQLSTATE[42S22]: Column not found: 1054 Unknown column ''city_count'' in 'field list'
(I had selected city in my form example).
I've tried the same code, except without the backticks around the placeholder :landtype (i.e. $sql = 'UPDATE players SET :landtype = :landtype + :tiles WHERE id = :id';) and I get a different error:
Error updating land count: SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''city_count' = 'city_count' + '300' WHERE id = '1'' at line 2
I'm not certain how to proceed. Does the attempt at setting the field value by creating a concatenated string break it here?
Don't try to bind column name like it's a value:
$sql = 'UPDATE players SET `'.$landtype.'` = `'.$landtype.'` + :tiles WHERE id = :id';
Can PHP PDO Statements accept the table or column name as parameter?
I have a form which i fill in a number and then the right database is updated. this is not working!
The variable gets posted (i had inserted 3 you see this in the error but its not updating)
i get this error? Error updating record: 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 ''3'_xyz_ips_short_code set content = replace(content,'eten','string_to_replace' at line 1
<textarea name="dbnaamsite" placeholder="3" cols="10" rows="1"></textarea>
$dbnaamsite = $_POST['dbnaamsite'];
$sql = "update wp_'$dbnaamsite'_xyz_ips_short_code
set content = replace(content,'eten','string_to_replace')";
//mysql_real_escape_string($formPostTitle);
Try it
$sql = "update `wp_".$dbnaamsite."_xyz_íp_short_code` set content = replace(content,'eten','string_to_replace')";
I'm not a newbie to PHP but I have encountered a [seemingly] simple problem which I cannot figure out how to resolve.
MySQL throws error that the syntax is wrong.
My Statement is this:
if($value){
$query = "UPDATE ".$preuploads." SET words = '$words_amount' WHERE id= $sn_id";
$db->sql_query( $query ) or die( mysql_error() );
}
And then $words_amount is an integer, $sn_id is also an integer. They are double checked.
The statement when printed before execution is as follows:
UPDATE SET uploads words = '250' WHERE id= 8081
// edited, with the name of table added since the problem primarily was
// with the encapsulation and the name of table just was dropped in this question
// and not in the app
however words value ('250') is tested with integer data-type as well, but no change occurs and the error lingers on.
And the error thrown is:
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 'SET words = '250' WHERE id= 8081' at line 1
If I understand your question (and preuploads is a table), then
$query = "UPDATE ".$preuploads." SET words = '$words_amount' WHERE id= $sn_id";
should be
$query = "UPDATE ".$preuploads." SET words = '".$words_amount."' WHERE id=".$sn_id;
Or, even better prepare and use bind_param,
$stmt = $mysqli->prepare("UPDATE ? SET words=? WHERE id=?");
$stmt->bind_param($preuploads, $words_amount, $snd_id);
$stmt->execute();
check your string ($words_amount) has any single quotes ' if it is then remove it by using this option on php $words_amount=string_replace("'","/'",$your_string_variable);
I have found two errors:
First, not encapsulation of the data should occur, thus:
$words_count should be left as is, not to be encapsulated with '
And the table and fields name should be encapsulated with backtick
I think your having problem with name of table. The syntax for update query is
UPDATE table_name SET words = '250' WHERE id= 8081
Am trying to only concat new updates to column updates and UPDATE the values in the rest of the columns but I've hit bit of a snag that I can't seem to workout.
My SQL looks like this:
$query="Update tickets SET product='$product',
p='$p',
i='$i',
summary='$summary',
workaround='$workaround',
concat(updates,'$additional_update'),
status='$status',
raised_by='$raised_by',
updated_by_user='$updated_by' WHERE id='$id'";
the updates column is like a comments column, where new updates are meant to be appended to the existing text.
The error I'm getting on the web server:
Update tickets SET product='T-Box', p='00000817766', i='-', summary='Testing update field
\r\nAdding an update\r\ntesting if null works for update', workaround='n/a', concat(updates,' ','test2#18:53:17:second update/n'), status='Open', raised_by='No', updated_by_user='test2' WHERE id='223'
Running the query directly in MySQL:
#1064 - 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 '(updates,'test2#18:53:17:second update/n'), status='Open', raised_by='No', updat' at line 1
Help is much appreciated!
You need to specify where the value of this statement concat(updates,'$additional_update') to be set.
Update tickets
SET product = '$product',
p = '$p',
i = '$i',
summary = '$summary',
workaround = '$workaround',
updates = CONCAT(updates,'$additional_update'), // <== see this
status = '$status',
raised_by = '$raised_by',
updated_by_user = '$updated_by'
WHERE id = '$id'
try this:
$query="Update tickets SET product='$product',
p='$p',
i='$i',
summary='$summary',
workaround='$workaround',
updates=concat(updates,'$additional_update'),
status='$status',
raised_by='$raised_by',
updated_by_user='$updated_by' WHERE id='$id'";
I am trying to do a basic mysql update but using AES_ENCRYPT - can anyone explain why i'm getting an error message? Below is the query :-
UPDATE MailList
SET Email = AES_ENCRYPT( arandomemail#hotmail.com, 'jkfdsfsaKJjdsf' )
WHERE ID = '138142'
I get the following error:
#1064 - 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 '#hotmail.co.uk,'jkaKJjkH87') WHERE MailListID = '138142'' at line 1
UPDATE MailList
SET Email = AES_ENCRYPT( 'arandomemail#hotmail.com', 'jkfdsfsaKJjdsf' )
WHERE ID = '138142'
You forgot the ' around your mail you want to encrypt.
UPDATE MailList
SET Email = AES_ENCRYPT( 'arandomemail#hotmail.com', 'jkfdsfsaKJjdsf' )
WHERE ID = 138142
You need to put the email address, arandomemail#hotmail.com, in quotes.
UPDATE MailList
SET Email = AES_ENCRYPT( 'arandomemail#hotmail.com', 'jkfdsfsaKJjdsf' )
WHERE ID = '138142'