Jump to content

[SOLVED] Extremely Newbie Question


Keith121

Recommended Posts

Please be kind...

 

I am writing a simple login script which will take the username and password information passed (via POST) from a form and compare them to information in a mysql database.

 

I am having trouble retrieving the information from the database. Here is my query:

 

$dbuser = mysql_query("SELECT * FROM profile WHERE login_id='$user'");

 

When a perform a var_dump I get this result:

 

resource(5) of type (mysql result)

 

How can I get the text string from my database so I can compare to what was entered in my initial form?

 

Thanks in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/149860-solved-extremely-newbie-question/
Share on other sites

mysql_query() returns a result resource. you then need to pull records from that result. in your case, there can only be one result:

$result = mysql_query("SELECT * FROM profile WHERE login_id='$user'") or die(mysql_error());
$dbuser = mysql_fetch_assoc($result);
print $dbuser['login_id'];

 

if your query had several records returned though, you would use a loop:

$result = mysql_query("SELECT * FROM profile") or die(mysql_error());
while($dbuser = mysql_fetch_assoc($result)){
  print $dbuser['login_id'];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.