This is a discussion on Embedding a variable in an SQL Query within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am getting the following error when running : $result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername"); $num_rows = mysql_num_rows($...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am getting the following error when running :
$result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername"); $num_rows = mysql_num_rows($result); Error = Warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in I:\Inetpub\wwwroot\protex\confirmation.php on line 37 in I:\Inetpub\wwwroot\protex\confirmation.php on line 37 |
|
|||
|
If i change $ThisUsername to an actual value in the database then it works
fine ie. change it to WHERE Username = 'Value1' "); but not as an embedded value. "Andy Levy" <andy_levy@hotmail.com> wrote in message news:bNNnb.4596$0E5.125@news-binary.blueyonder.co.uk... > I am getting the following error when running : > > $result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername"); > $num_rows = mysql_num_rows($result); > > Error = > Warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL > result resource in I:\Inetpub\wwwroot\protex\confirmation.php on line 37 in > I:\Inetpub\wwwroot\protex\confirmation.php on line 37 > > |
|
|||
|
Try the following, which will output the cause of the problem:
$result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername") or die("mysql_query failed - Error: " . mysql_error()); $num_rows = mysql_num_rows($result); "Andy Levy" <andy_levy@hotmail.com> wrote in message news:bNNnb.4596$0E5.125@news-binary.blueyonder.co.uk... I am getting the following error when running : $result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername"); $num_rows = mysql_num_rows($result); Error = Warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in I:\Inetpub\wwwroot\protex\confirmation.php on line 37 in I:\Inetpub\wwwroot\protex\confirmation.php on line 37 |
|
|||
|
*** Andy Levy wrote/escribió (Wed, 29 Oct 2003 11:54:57 -0000):
> If i change $ThisUsername to an actual value in the database then it works > fine ie. change it to > > WHERE Username = 'Value1' "); > > but not as an embedded value. How do you set your variable? $ThisUsername="Value1"; or $ThisUsername="'Value'"; First way will fail if it isn't a numeric field. >> $result = mysql_query("SELECT * FROM users WHERE Username = > $ThisUsername"); -- -- -- Álvaro G. Vicario - Burgos, Spain -- |
|
|||
|
you're just missing the quotes. try this: $result = mysql_query('select * from users where Username ="'.$ThisUsername.'"); "Andy Levy" <andy_levy@hotmail.com> wrote in message news:LUNnb.4672$0E5.1308@news-binary.blueyonder.co.uk... If i change $ThisUsername to an actual value in the database then it works fine ie. change it to WHERE Username = 'Value1' "); but not as an embedded value. "Andy Levy" <andy_levy@hotmail.com> wrote in message news:bNNnb.4596$0E5.125@news-binary.blueyonder.co.uk... > I am getting the following error when running : > > $result = mysql_query("SELECT * FROM users WHERE Username = $ThisUsername"); > $num_rows = mysql_num_rows($result); > > Error = > Warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL > result resource in I:\Inetpub\wwwroot\protex\confirmation.php on line 37 in > I:\Inetpub\wwwroot\protex\confirmation.php on line 37 > > |
|
|||
|
On 29-Oct-2003, "Andy Levy" <andy_levy@hotmail.com> wrote: > I am getting the following error when running : > > $result = mysql_query("SELECT * FROM users WHERE Username = > $ThisUsername"); > $num_rows = mysql_num_rows($result); > > Error = > Warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL > result resource in I:\Inetpub\wwwroot\protex\confirmation.php on line 37 > in > I:\Inetpub\wwwroot\protex\confirmation.php on line 37 Unless Username is numeric you need quotes around the value, try: $result = mysql_query("SELECT * FROM users WHERE Username = '$ThisUsername' "); -- Tom Thackrey www.creative-light.com tom (at) creative (dash) light (dot) com do NOT send email to jamesbutler@willglen.net (it's reserved for spammers) |
![]() |
| Thread Tools | |
| Display Modes | |
|
|