Page 1 of 1

mySQL UPDATE statement

PostPosted: 01. January 2013 02:22
by bogey
Thank you in advance.

Windows 8
XAMPP 1.8.1
Apache 2.4.3
MySQl 5.5.27 (Community Server)
PHP 5.4.7 (VC9 X86 32bit thread safe) + PEAR
OpenSSL 1.0.1c
XAMPP Control Panel v3.1.0 3.1.0

Apache and MySQL Service Modules showing green.
Apache and MySQL Running.

With the UPDATE statement, The program does not compile giving the following error;

Parse error: syntax error, unexpected 'customer' (T_STRING) in C:\xampp\htdocs\project\connect\DelUser2.php on line 28

customer is the name of the table in Database jq2.
UPDATE statement works in the phpmyadmin(SQL window) but not when running the .php file in the browser.
I gave global privileges to localhost for the database and the customer table.
INSERT AND DELETE statements function correctly.
-----------------------------------------------------------------------------------------------------

<?php
$mysqli = new mysqli('localhost', 'root', 'pass', 'jq2');
if (!$mysqli)
{
die('mysqli_init failed');
}

if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0'))
{
die('Setting MYSQLI_INIT_COMMAND failed');
}

if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 30))
{
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}

if (!$mysqli->real_connect('localhost', 'root', 'pass', 'jq2'))
{
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}

/* this succeeds */

echo 'Success... ' . $mysqli->host_info . '<br>';

/* UPDATE fails to be compiled */
UPDATE customer SET MemId=1 WHERE ID=0 ORDER BY UserName LIMIT 1 ;

$mysqli->close();
?>

Re: mySQL UPDATE statement

PostPosted: 01. January 2013 05:11
by Altrea
Hi bogey,

bogey wrote:Parse error: syntax error, unexpected 'customer' (T_STRING) in C:\xampp\htdocs\project\connect\DelUser2.php on line 28
Code: Select all
[...]
echo 'Success... ' . $mysqli->host_info . '<br>';

/* UPDATE fails to be compiled */
   UPDATE customer SET MemId=1 WHERE ID=0 ORDER BY UserName LIMIT 1 ;

$mysqli->close();
?>


You write down the statement simply in php context without any function. What do you expect!?
You have to use a function like mysqli::query for that.

best wishes,
Altrea

P.S.:
bogey wrote:I gave global privileges to localhost for the database and the customer table.

You can't grant table priviledges to whole database hosts, but to database users.

bogey wrote:INSERT AND DELETE statements function correctly.

I don't believe that any SQL-statement will gets executed without the specific php function to call. How should php know what to do with that text?

Re: mySQL UPDATE statement

PostPosted: 12. January 2013 18:38
by bogey
Thanks for your input altrea, problem solved.