Mysqli .Field value not getting updated - php

I am trying to update a field when particular function is called but its value is not getting updated in db . And also no errors showing up . Field type is text .
I tried by adding new field to table and then updated that field in my query and it worked fine, but after some time same issue with new field .
$con=mysqli_connect("localhost","username","password","dbname");
mysqli_query($con,"UPDATE sales_flat_quote SET extra_params = 'aaa',new_params = 'bbb' WHERE entity_id = 362214") or die(mysqli_error($con));
Above query was working earlier but later it doesn't update the value in database and if you run query directly on phpmyadmin it works fine .
Any Ideas ?

There's an error in your syntax, you forgot to close the double quote:
mysqli_query($con,"UPDATE sales_flat_quote SET extra_params = 'aaa',new_params = 'bbb' WHERE entity_id = 362214") or die(mysqli_error($con));
This should work. Syntax coloring is your friend ;)

Related

using update statement in php

I am trying to update my database using php however my update clause is not working.
This is the code:
<?php
if (isset($_POST['submit']))
{
date_default_timezone_set('Australia/Sydney');
$date = date("Y-m-d h:i:s");
$sqlUpdate = " UPDATE booking
SET checkedin = '1', checkin_datetime = '$date'
WHERE id = '$flightID'";
$result3 = mysqli_query($dbConn, $sqlUpdate) or trigger_error("Query Failed! SQL: $sqlUpdate - Error: ".mysqli_error($dbConn), E_USER_ERROR);
}
?>
In my database the flightID is an auto increment integer and the checkin is a tiny int.
I believe that it could be treating my variable as a string and not a integer which is why it is not updating in my database.
I have tried creating a variable to to hold the value of 1 and replace it with the hard coded value in the SQL which did not change anything.
Any ideas what the problem is and how to fix it?
here is a photo for my booking table
please note in my sql the 'flightID' variable is actually referring to the id column in the booking table

Updating database entry using PHP not working for text fields

Im trying to run the following code but it is giving me a strange error..
$result = $db->query("UPDATE `items`
SET `item_label`= ".$title.",
`item_quantity`=".$quantity.", `item_price`=".$price."
WHERE `item_id` = ".$_POST['id']);
If i remove the item_label = ".$title.", from the above code it works perfectly and successfully updates the quantity and price of the given row. e.g.
$result = $db->query("UPDATE `items`
SET `item_quantity`=".$quantity.",
`item_price`=".$price."
WHERE `item_id` = ".$_POST['id']);
when I run the code containing the item_label section it fails to set the item_label. and it gives the following error message..
Unknown column 'Updated Text' in 'field list'
Now the "Updated Text" is the value of $title.
Im baffled as to how / why it is viewing this content as a column header!?
any ideas as to why this would happen?
Since its a String you should give quotes around the $title
I would have done something like below
$result = $db->query("UPDATE items SET item_label = '".$title."', item_quantity=$quantity,item_price=$price WHERE item_id =$_POST['id']");

How to update a row depending on a condition

I try to update a row in my database. i receive no error but the update does not happend
$sql = "UPDATE calendar_events
SET event_title='".$_POST["naam"]."'
WHERE id ='($event_id)'";
problem is by variable $event_id. If i place a nummber in place of $event_id ( WHERE id =6)
then it is ok and i have my update but any he do not accept any variable
I did change a lot of things. The type of variabls id and $event_id are the same. De value of the id and $event_id are de same . i did try with $event_id, and '".$event_id."'. every thing is ok
and no erroror from database bat the update do not happen.
can someone help me
thanks
Try with
$sql = "UPDATE calendar_events
SET event_title='".$_POST["naam"]."'
WHERE id ='$event_id'";
Otherwise, you are comparing it with (1), (2) or whatever number it has, but with parenthesis.
UPDATE: and, of course, SANITIZE your $_POST variables!!!

PHP/MySQL Concat to a single column and Update other columns in table

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'";

After SQL update, field is set to 0 [PHP/MySQL]

Okay, I'm currently sick so maybe the answer is right in front of me but I've been sitting here for the past 4 hours trying to figure out why this is happening.
Basically I have a script that is supposed to update a row in the database.
The field I'm trying to update is 'name' and it looks like this:
// Updating the database with the new name
$name = $this->db->slashes( $this->friends[$row->key] );
$sql = "UPDATE `friends` SET `name` = '" . $name . "' AND `status` = 'updated' WHERE `key` = " . $row->key . " LIMIT 1";
echo '-- Query: ' . $sql . '<br />';
$result2 = $this->db->query( $sql );
if( !$result2 )
echo mysql_error();
Output becomes this(an example):
-- Query: UPDATE `friends` SET `name` = 'Andrew Johnsson' AND `status` = 'updated' WHERE `key` = 7823583 LIMIT 1
It did not generate any mysql_error so the query seem to have gone through properly and by the looks of the query, it should have just updated a row in the database where the key was a number and set the new name to Andrew Johnsson aswell as setting status to updated.
However! After looking in the database after this update, the name for this row is set to '0'. Why on earth did it do that?
Any ideas as to why this is happening?
Also, tell me if you need some more information to be able to help me and I'll kindly provide it!
Your UPDATE syntax is incorrect. It should be SET name = 'string', status = 'updated' WHERE key...
Currently you are literally asking it to evaluate the AND's in order to determine what the name column should be updated with, which is why you're getting the 0.
Well, this might be too silly, but name is a string field, right? If it's set to any kind of integer field, this is exactly what would happen: the string is parsed as 0.
I bet it's something a wee bit more complicated than that, though.

Categories