Jump to content

Archived

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

Boerboel649

Selecting specific entry in MySQL database and converting it to a variable

Recommended Posts

OK, I'm sure this is pretty simple...

OK, say we have a table, that has usernames and passwords, and field with a specific URL fo each user.  What I want to do, is based on the username and password submitted, I want to convert the URL in the URL field to a variable...  Something like this, but not sure what to do to select the URL...

$query = "SELECT * FROM yourtable WHERE username = '$user' AND userpassword = '$pass'";

Now how do I select the URL for that user, and then convert it to a variable?
Like...

$url = blah blah blah

Let me know if I didn't explain myself well enough. :D
Thanks!!!!!!

Share this post


Link to post
Share on other sites
Assuming the name of the field in the database is "url":
[code]<?php
$query = "SELECT * FROM yourtable WHERE username = '$user' AND userpassword = '$pass'";
$rs = mysql_query($query) or die('Problem with the query: $query<br>" . mysql_error());
$rw = mysql_fetch_asssoc($rs);
$url = $rw['url'];
echo $url;
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Hmmm... I'm helping someone out on another forum (integrating some Flash with the PHP) and he's getting this error.....

Fatal error: Call to undefined function: mysql_fetch_asssoc() on line 18

Which line 18 looks like this....

$rw = mysql_fetch_asssoc($rs);

P.S.  This...
$rs = mysql_query($query) or die('Problem with the query: $query<br>" . mysql_error());

Should be this...

$rs = mysql_query($query) or die('Problem with the query: '.$query.'<br />' . mysql_error());

... I think...

Share this post


Link to post
Share on other sites
I misspelled the function --- it should be mysql_fetch_assoc() ...

Ken

Share this post


Link to post
Share on other sites

×

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.