Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
mysql_insert_id bullcrap problem
Old 05-27-2005, 01:50 PM mysql_insert_id bullcrap problem
Novice Talker

Posts: 6
Trades: 0
Hi there.

I made something so people can register with they email adress and they get given a unique id.

now i would like it so when you go to mysite.com/index.php?their_id_here the page will be able to find out their email address to display from the id.

Last edited by 0beron; 05-27-2005 at 06:49 PM..
JoeP is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-27-2005, 08:59 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Hi,

I presume the person is logging in via a form and then gets re-directed to mysite/index.php?their_id_here.

I take it the username and password are stored in the same database table as the user_id and e-mail. If this is the case, I also presume the login queries the database to find the correct username/password combination and retrieves the user_id if a match is found.

Instead of just pulling the user_id, use the same select query to pull the e-mail address as well.

This should work okay

Regards
Ian
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE

Last edited by celticbrue; 05-27-2005 at 09:05 PM..
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 05-28-2005, 04:28 AM
Novice Talker

Posts: 6
Trades: 0
They dont get redirected to mysite/index.php?their_id_here because im not really sure how to do it.

I dont know sql really but so far i have managed to write a form in where you type your email address and when you click submit the page will display something like, "Your unique ID is: 05".

Now i want to make it, so when you go to mysite/index.php?their_id_here the page will know the email adress of the user, working it out from the ID in the url.
JoeP is offline
Reply With Quote
View Public Profile
 
Old 05-28-2005, 05:50 AM
HitRaj47's Avatar
Extreme Talker

Posts: 177
Location: GA
Trades: 0
you can use the header() function to redirect them. so

<?php
header ("Location: mysite/index.php?id=" . urlencode($id));
exit;
?>

of make sure $id set as the unique ID (you can get it the same way you get the ID when you print it).

to get the username from the URL

PHP Code:
$id $_GET['id'];

// Connect and select the database
mysql_connect ('localhost''username''password');
mysql_select_db ('your_db');

// Define the sql query to get the email
$sql "SELECT email FROM you_users_table WHERE id = '$id'";

// Run the query
$result mysql_query($sql);

// Assign the emai to a variable
$email mysql_result($result0);    // $email = what ever the email that was returned from the query, assuming it exists

// Close the database connection
mysql_close();

// Print their email
print "Your email address is: <strong>" $email "</strong>"
HitRaj47 is offline
Reply With Quote
View Public Profile
 
Old 05-28-2005, 06:43 AM
Novice Talker

Posts: 6
Trades: 0
Im getting an error with one of the lines you gave me "$email = mysql_result($result, 0); // $email = what ever the email that was returned from the query, assuming it exists "

The error is : Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in /home/splinter/public_html/gamersport/temp/page.php on line 14
Your email address is:

Also, is this correct?

$id = $_GET['mysql_insert_id()'];

header ("Location: page.php?id=" . urlencode($id));
exit;

Last edited by JoeP; 05-28-2005 at 07:55 AM..
JoeP is offline
Reply With Quote
View Public Profile
 
Old 05-29-2005, 08:26 AM
HitRaj47's Avatar
Extreme Talker

Posts: 177
Location: GA
Trades: 0
see what is returned from the query

put this somewhere in the page [you can delete later, it just for testing atm]:

PHP Code:
<?php
$id 
$_GET['id'];    // This should be the unique ID

mysql_connect ('localhost''username''password');
mysql_select_db('your_db');

$sql "SELECT email FROM your_table WHER id = '$id'";

$result mysql_query($result);

while (
$row mysql_fetch_array ($result)) {    // This will runt he query and display all the results
    
print "ID: " $row['id'] . " | Email: " $row['email'] . "<br />";

}

mysql_close();

?>
also make sure email is the right name for the field in the database

"Also, is this correct?

$id = $_GET['mysql_insert_id()'];"

Not sure.
HitRaj47 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql_insert_id bullcrap problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23355 seconds with 12 queries