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
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'];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.