mySQL UPDATE statement

Problems with the Windows version of XAMPP, questions, comments, and anything related.

mySQL UPDATE statement

Postby bogey » 01. January 2013 02:22

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();
?>
bogey
 
Posts: 4
Joined: 16. September 2012 19:00
XAMPP Version: 5.6.3
Operating System: Windows8

Re: mySQL UPDATE statement

Postby Altrea » 01. January 2013 05:11

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?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6763
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: mySQL UPDATE statement

Postby bogey » 12. January 2013 18:38

Thanks for your input altrea, problem solved.
bogey
 
Posts: 4
Joined: 16. September 2012 19:00
XAMPP Version: 5.6.3
Operating System: Windows8


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 29 guests