Jump to content

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


Boerboel649

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!!!!!!

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

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.