I'm hoping someone can spot my mistake in this MySQL query.
UPDATE 'databasename'.'tablename'
SET fieldB = fieldB + 1
WHERE fieldA = '2';
I'm basically trying to add 1 to the current value of fieldB where fieldA is i.e 2.
First, you must specify the name of the table. After that, in parenthesis, you must specify the column name of the table, and columns must be separated by a comma. The values that you want to insert must be inside the parenthesis, and it must be followed by the VALUES clause.
In MySQL “Where 1=1” results in all the rows of a table as this statement is always true. An example to better unerstand this statement is given as follows − First, a table is created with the help of the create command.
preferred way, using MySQLi extension: $mysqli = new mysqli(SERVER, DBUSER, DBPASS, DATABASE); $result = $mysqli->query("SELECT id FROM mytable WHERE city = 'c7'"); if($result->num_rows == 0) { // row not found, do stuff... } else { // do other stuff... }
Single-quotes are for strings.
UPDATE `databasename`.`tablename`
SET fieldB = fieldB + 1
WHERE fieldA = '2';
You can use backticks around the database and tablenames; they aren't strictly necessary though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With