Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-08-20, 03:24 PM
Junior Member
 
Join Date: Aug 2004
Posts: 2
pejdmvman
Default

Hello,

I am having trouble getting a MySQL UPDATE SET query to work. The query is being sent from a web page using PHP to deliver the comand. Below is the snippit of code that is trying to perform an update. I know the $conn = my_conn; works to connect me to the db, besides which, the error that I am getting (see error at bottom of message) is a syntax error and not a connection error as indicated by the error message.

The snippit of code shown below is contained withing a function which I know is being called correctly as I CAN get it to echo something to the screen when called with an echo inside the function as a test.

$conn = my_conn();

/* DEFINE QUERIES THAT WILL APPEND DATA BEING SENT FROM */

/* get_data() (above) INTO THE VARIOUS FIELDS IN THE DTATABASE. */
$sql_update = "UPDATE client SET ";
$sql_update .= "client.client_id = '" . $_REQUEST['client_id'] . "', ";
$sql_update .= "client.client_name = '" . $_REQUEST['client_name'] . "', ";
$sql_update .= "WHERE client.client_id = " . $_REQUEST['client_id'] . ")";
// ----------------------------
// END DEFINE QUERIES....
// ----------------------------




// ----------------------------------
// PASS QUERY (above) TO DATABASE.
// ----------------------------------
$result = mysql_query($sql_update, $conn);

if (!$result) {
echo("

Error performing query: " . mysql_error() . "</p>");
exit();
}

/* Prints succes message */

print "

Successfully Updated</p>";

/* closes connection */

mysql_close ($conn);

____________________
THE ERROR MESSAGE
____________________

Error performing query: You have an error in your SQLsyntax near 'WHERE client.client_id = 1)' at line 1

___________________
END ERROR MESSAGE
___________________

client_id is a field within the table 'client' and is set as an integer as well as the primary key and was set to null upon creation.

I have been looking at various examples of the syntax to be used for what I am trying to accoplish and while I can understand how most of what I've seen works, those examples do not resemble the example I have shown above (which I tweaked slightly from the following exaple: http://www.keithjbrown.co.uk/vworks/php/php_p5.php). Take a look at the syntax the auther of that exmple uses and you should see that it is the same?

Any assistance I can get in determining why I still get the error would be appreciated. I have tried many different variotions of the WHERE clause to try and fix but can't get rid of the darnd error.

Thanks in advance!

Soulfolk
Reply With Quote
  #2 (permalink)  
Old 2004-08-20, 03:41 PM
Junior Member
 
Join Date: Aug 2004
Posts: 2
pejdmvman
Default

Soulfolk here, the auther of the above question.

Please be aware that in the above code example there is a "(" missingfrom:

1. - "WHERE client.client_id = " . $_REQUEST['client_id'] . ")";

should be

"WHERE (client.client_id = " . $_REQUEST['client_id'] . ")";

Notice the added '(' in this example of the dode snippet.

2. - Error performing query. You have an error in your SQL syntax near 'WHERE (client.client_id = 1)' at line 1.

Sorry I missed those on the original question above.
Again, any help in resolving this issue s greatly appreciated.

Sincerely,
Soulfolk

Again notice the added '(' in this example of the error message.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:30 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.