Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 09 July 2006 - 04:34 PM

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



#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 04:37 PM

Assuming the name of the field in the database is "url":
<?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;
?>

Ken

#3 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 10 July 2006 - 01:56 AM

Thanks a BUNCH!!!!!! 

#4 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 11 July 2006 - 09:10 PM

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

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 July 2006 - 09:14 PM

I misspelled the function --- it should be mysql_fetch_assoc() ...

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users