a little trouble with mysql_result

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jonah
Forum Commoner
Posts: 31
Joined: Fri Jun 20, 2003 12:23 am

a little trouble with mysql_result

Post by jonah »

I am trying to assign query output to variables in the standard way:

$result=mysql_query("SELECT * FROM Table1 WHERE Ident=$str",$db);

$ident=mysql_result($result,0,"Ident");
$user=mysql_result($result,0,"Username");
$pass=mysql_result($result,0,"Password");
$pin=mysql_result($result,0,"Pin");
$alt=mysql_result($result,0,"Alt");
$lot=mysql_result($result,0,"Lot");

The only difference between this coding and a more generalized
query is that I am not using a counter variable ($i) to iterate over
several records. This query only returns a single record.

I keep getting the error message:

PHP Warning: mysql_result(): supplied argument is not a valid MySQL result resource

Is there any reason why I cannot simply use the index '0' here to
assign the results? Or is something else wrong (like bad query)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you likely have an error in your mysql_query call.. standard troubleshooting of queries:

Code: Select all

$result = mysql_query("SELECT * FROM Table1 WHERE Ident=$str",$db) or die(mysql_error());
Post Reply