RE: [PHP] R: [PHP] SQL Query Not Kosher?
On 03 February 2004 13:45, Alessandro Vitale contributed these pearls of wisdom: > try removing curly braces as follows: > > $query = mysql_query("UPDATE stories SET status='approved' >WHERE story_id={$id}"); | Nothing wrong with the above, it's perfectly valid -- just a slightly different way of writing: > $query = mysql_query("UPDATE stories SET status='approved' > WHERE story_id=${id}"); Cheers! Mike -- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] R: [PHP] SQL Query Not Kosher?
try removing curly braces as follows: $query = mysql_query("UPDATE stories SET status='approved' WHERE story_id={$id}"); | | | \/ $query = mysql_query("UPDATE stories SET status='approved' WHERE story_id=$id"); or $query = mysql_query("UPDATE stories SET status='approved' WHERE story_id=${id}"); this applies if story_id is of type int in mysql table definition, or you should enclose it among '' if is of type char, varchar or similar. cheers alessandro -Messaggio originale- Da: Mr. Austin [mailto:[EMAIL PROTECTED] Inviato: martedì 3 febbraio 2004 5.35 A: [EMAIL PROTECTED] Oggetto: [PHP] SQL Query Not Kosher? Hi all: I am trying to get this to work, but always get the same error: that the resource in mysql_affected_rows() is not valid. Anyone see why this would be? All variables have been tested for accuracy. $query = mysql_query("UPDATE stories SET status='approved' WHERE story_id={$id}"); if(mysql_affected_rows($query) == 1) { print("Your approval of \"$title\" was successful. If this user entered an email address, they have been sent a notice of its approval and publication on the site."); } else { print("The approval of \"$title\" was not successful. Please check with the site administrator for assistance."); } The above SQL statement works perfectly with phpMyAdmin (and, oddly enough, works with the above script, yet the Warning is produced and the 'not successful' message is displayed) Any thoughts are appreciated! Mr. Austin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SQL Query Not Kosher?
The argument to mysql_affected_rows must be mysql CONNECTION identifier (from mysql_connect), not RESULT identifier (from mysql_query). Removing the argument will work for you. Mr. Austin wrote: Hi all: I am trying to get this to work, but always get the same error: that the resource in mysql_affected_rows() is not valid. Anyone see why this would be? All variables have been tested for accuracy. $query = mysql_query("UPDATE stories SET status='approved' WHERE story_id={$id}"); if(mysql_affected_rows($query) == 1) { print("Your approval of \"$title\" was successful. If this user entered an email address, they have been sent a notice of its approval and publication on the site."); } else { print("The approval of \"$title\" was not successful. Please check with the site administrator for assistance."); } The above SQL statement works perfectly with phpMyAdmin (and, oddly enough, works with the above script, yet the Warning is produced and the 'not successful' message is displayed) Any thoughts are appreciated! Mr. Austin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SQL Query Not Kosher?
That would explain why it displays the second message saying it was not successful. But why then does it still display this warning? Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\apache\htdocs\admin\stories.php on line 112 Mr. Austin - Original Message - From: "Jochem Maas" <[EMAIL PROTECTED]> To: "Mr. Austin" <[EMAIL PROTECTED]> Sent: Monday, February 02, 2004 10:41 PM Subject: Re: [PHP] SQL Query Not Kosher? > from the php function manual: > > > Note: When using UPDATE, MySQL will not update columns where the new > value is the same as the old value. This creates the possibility that > mysql_affected_rows() may not actually equal the number of rows matched, > only the number of rows that were literally affected by the query. > > > http://nl2.php.net/mysql_affected_rows > > Mr. Austin wrote: > > > Hi all: > > > > I am trying to get this to work, but always get the same error: that the resource in mysql_affected_rows() is not valid. Anyone see why this would be? All variables have been tested for accuracy. > > > > $query = mysql_query("UPDATE stories SET status='approved' WHERE story_id={$id}"); > > if(mysql_affected_rows($query) == 1) { > > print("Your approval of \"$title\" was successful. If this user entered an email address, they have been sent a notice of its approval and publication on the site."); > > } else { > > print("The approval of \"$title\" was not successful. Please check with the site administrator for assistance."); > > } > > > > The above SQL statement works perfectly with phpMyAdmin (and, oddly enough, works with the above script, yet the Warning is produced and the 'not successful' message is displayed) Any thoughts are appreciated! > > > > Mr. Austin > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] SQL Query Not Kosher?
Hi all: I am trying to get this to work, but always get the same error: that the resource in mysql_affected_rows() is not valid. Anyone see why this would be? All variables have been tested for accuracy. $query = mysql_query("UPDATE stories SET status='approved' WHERE story_id={$id}"); if(mysql_affected_rows($query) == 1) { print("Your approval of \"$title\" was successful. If this user entered an email address, they have been sent a notice of its approval and publication on the site."); } else { print("The approval of \"$title\" was not successful. Please check with the site administrator for assistance."); } The above SQL statement works perfectly with phpMyAdmin (and, oddly enough, works with the above script, yet the Warning is produced and the 'not successful' message is displayed) Any thoughts are appreciated! Mr. Austin