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

Link to comment
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
Link to comment
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...
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.