$query=UPDATE americana SET 7='99' WHERE Bdate='2011-04-15';
mysql_query($query);
7 is a column name and Bdate too
it doesn't update my table?
if so enclose it with backtick "`"
$query="UPDATE americana SET `7`='99' WHERE Bdate='2011-04-15'";
$query="UPDATE americana SET `7`='99' WHERE Bdate='2011-04-15'";
mysql_query($query);
The query should be enclosed in quotes and also marked column name with backtick(`)sign if it has name with starting from numeric value, try it now and see if it works better now...
Related
I am not able to update MySQL table using PHP. How can I do that?
I have tried by changing the order of double quotes.
$name=mysql_real_escape_string($_POST["steel"]);
$db->execute("UPDATE order SET need=$name WHERE raw-id='1'");
It should store $name in the database.
You should wrap your $name with single quote, because you are trying to pass a string into the SQL
$db->execute("UPDATE order SET need='$name' WHERE `raw-id`='1'");
You should wrap your {$name} with single quote and bracket to , because need row is a string into the SQL
$db->execute("UPDATE order SET need='{$name}' WHERE `raw-id`='1'");
You need to wrap your column name in back-ticks because it has a dash in it, e.g:
$db->execute("UPDATE order SET need = '$name' WHERE `raw-id` = 1");
By referring to the manual I think you should first prepare your
query and then use execute() method. Something like this:
$query = "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)";
$stmt = $mysqli->prepare($query);
$stmt->execute();
This query had previously worked, now when it is run again we get Unknown Column in field list error.
The query works well if we do not use variables and set raw data. The columns match those in the database.
$update_order_id = "UPDATE order_tbl SET o_process=$process, o_payment=$payment, o_paymentType=$paymenttype WHERE o_id=$orderid AND o_active='1'";
You need wrap single quotes for the values in the query as
o_process='$process'
etc
So the query will be as below. For string values its necessary.
$update_order_id = "UPDATE order_tbl
SET o_process='$process',
o_payment='$payment',
o_paymentType='$paymenttype'
WHERE o_id= '$orderid' AND o_active='1'";
You might need to surround your variables with quotes, only integer columns doesn't need quotes.
$update_order_id = "UPDATE order_tbl SET o_process='$process', o_payment='$payment', o_paymentType='$paymenttype' WHERE o_id='$orderid' AND o_active='1'";
I want to update 2 columns of a table, I've echoed the $sql1, it is showing dates what I want(y-m-d) to insert into database, but when I fire the query, dates were updated as 0000-00-00 (y-m-d) in database.
output of echo $sql1
UPDATE member SET
reg_date='2014-03-05' AND expiry='2014-03-06'
WHERE bill_id='9'
following are my query statements--
$sql1="UPDATE member SET
reg_date='$date1' AND expiry='$date'
WHERE bill_id='$_REQUEST[bid]'";
mysql_query($sql1,$con)or die(mysql_error());
Can you please solve the error?
The correct syntax is to separate by commas in your SET clause.
UPDATE table
SET field1 = 1, field2 = 2, field3 = 3
WHERE field = 1
In your case:
$sql1="UPDATE member
SET reg_date='$date1', expiry='$date'
WHERE bill_id='" . $_REQUEST[bid] . "'";
mysql_query($sql1,$con)or die(mysql_error());
I also separated out your WHERE clause, as it looks as if it may have trouble parsing the string.
You should separate your values with commas, not with and
$sql1="update member set reg_date='$date1', expiry='$date' where bill_id='$_REQUEST[bid]'";
$sql1="update member set reg_date='$date1', expiry='$date' where bill_id='$_REQUEST[bid]'";
You should not use "and" to separate values, instead you can use "commas" to separate values.
Why is it, that I can't UPDATE a field (type:longtext) with a string that contains a comma (,)...
$result=mysql_query("UPDATE table_name SET column1=$a WHERE column2=$b AND column3='price'");
Works well with
$a="10"; or $a="10.99";
$b="15";
doesn't work with
$a="10,99";
$b="15";
neither works with:
$a="10,99";
$a=mysql_real_escape_string($a);
What am I doing wrong here?
When your query string is being evaluated with the values that contain commas, this is the query:
"UPDATE table_name SET column1=10,19 WHERE column2=15 AND column3='price'";
The comma is creating an issue because the value 10,19 is not a string. You need to put quotes around your variables. If you use double-quotes, you will need to escape the quotes. Single quotes work as well; either of the following should do the trick:
$result=mysql_query("UPDATE table_name SET column1=\"$a\" WHERE column2=\"$b\" AND column3='price'");
or
$result=mysql_query("UPDATE table_name SET column1='$a' WHERE column2='$b' AND column3='price'");
Change (you need to wrap string or text type of field with ')
$result=mysql_query("UPDATE table_name SET column1=$a WHERE column2=$b AND column3='price'");
To
$result=mysql_query("UPDATE table_name SET column1='$a' WHERE column2='$b' AND column3='price'");
I'm trying to insert a new record into a table 'order'. Here is the code:
$orderDB = mysql_query("INSERT INTO order (itemsID, deliveryDestinationID, total, shipped) VALUES ($itemID, $delivery, $totalprice, 'N')") or die(mysql_error());
The variables are $itemID which is a 5 digit number, $delivery which is also a 5 digit number, $totalprice which is the cost of the transaction (e.g. 137.97) and 'N' which is used in a shipped field in my table.
I think the issue is coming from $totalprice, however when I echo all the variables before this line they appear to be correct. Here is an example of the echo's and error when $totalprice is 170:
00036 00022 N 170 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 'order (itemsID, deliveryDestinationID, total, shipped) VALUES (00036, 00022, 170' at line 1
Any ideas?
order is a reserved word in MySQL. Consider changing the table name or wrap it in backticks (eg: `order`)
http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
ORDER is a reserved keyword. Escape it with backticks if you use it as table name:
"INSERT INTO `order` (itemsID ...
ORDER is a MySQL reserved keyword. To use it as a table or column name you must enclose it in backticks.
$orderDB = mysql_query("INSERT INTO `order` (itemsID, deliveryDestinationID, total, shipped) VALUES ($itemID, $delivery, $totalprice, 'N')") or die(mysql_error());
order is a reserved keyword. It is the source of error in your query. As others suggested enclose it in back-ticks for the query to work.