|
|
Hey, I have a user system at my site, where members can login, and only access some pages if they are logged in. I got the member system from www.rmb-scripting.com. I got a tutorial for a member to change their password by a pincode, and I started to make a script that allows members to change their Pincode. Heres the part I am having problems on:
| Code: | case 'send':
$checkuser = $logged[username];
$email = mysql_query("SELECT email FROM members WHERE username = '$checkuser' ORDER BY id DESC") or die (mysql_error());
echo "$email";
break; |
Okay to start off.
1. There is no mysql_errors (or none that show at this point)
2. The rest of the code works
3. This code above takes the email for the user (and the user is defined by a variable called "$checkuser".
4. This code SHOULD show the email of the user that is logged in, but instead it gives me this:
Does anybody have any ideas why it shows that resource code instead of the users email?
Thanks!
| Diablosblizz wrote: | 4. This code SHOULD show the email of the user that is logged in, but instead it gives me this:
|
No it shouldn't. If you want to do that;
| Code: | case 'send':
$checkuser = $logged[username];
$email = mysql_query("SELECT email FROM members WHERE username = '$checkuser' ORDER BY id DESC") or die (mysql_error());
$email = mysql_fetch_assoc($email);
echo $email['email'];
break; |
You need to actually do something with the resulting resource. Here I've used mysql_fetch_assoc though you could also use row, array or object. 
Okay, because I don't want to echo the users email, I would put it into variable, because I want it to just it in the mail function. So I did this:
| Code: | | $getemail = $email['email']; |
Then I added this for the mail:
| Code: | | mail("$getemail", "Subject: Pin Reminder", $mail, "From: $site Pin Code Reminder"); |
I have defined $mail, but when I go to that page, it says this:
| Code: | | A email has been sent to Array |
It should say (example):
I don't know what I did wrong.
EDIT: Just noticed that it sent the email, but did not do many of the things I wanted it to do. I still need help on that email bit..
| Code: |
case 'send':
$checkuser = $logged[username];
$email = mysql_query("SELECT email FROM members WHERE username = '$checkuser' ORDER BY id DESC") or die (mysql_error());
$fetch = mysql_fetch_array($email);
mail($fetch['email'], "Subject: Pin Reminder", $mail, "From: $site Pin Code Reminder");
break;
|
If it's send to an array, then you have multiple rows in your mysql table. You should check if there is more than 1 username with $checkuser in the table 
I tried doing that (it worked for the email tyvm), but in the email I want it to show the pin that the user changed to. I tried this:
| Code: | $pin = mysql_query("SELECT pincode FROM members WHERE username = '$checkuser' ORDER BY id DESC") or die (mysql_error());
$fetchpin = mysql_fetch_array($pin); |
In the $mail i put:
| Code: | | $fetchpin or $fetchpin[pin] |
I can't put the ' or ' because the echo is in " and " and it gives me an error. Anybody have any ideas?
If you put a limit on the number of returned results then you will only get 1 returned pincode. I assume that you are working on the assumption that each member has a unique username? (you can define this in the MySQL table definition):
| Code: |
$pin = mysql_query("SELECT pincode FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchpin = mysql_fetch_assoc($pin);
$current_user_pin = $fetchpin['pincode'];
|
You can then put $current_user_pin in the email:
| Code: |
$email_message = "Your pincode is $current_user_pin and please go here to change your password etc etc.";
|
This does not work. Because you might be confuzzed here is my current code:
| Code: | case 'send':
$pin = mysql_query("SELECT pincode FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchpin = mysql_fetch_assoc($pin);
$current_user_pin = $fetchpin['pincode'];
$mail = "You have selected a reminder from $sitename for your Pin Number. \r
A pin number allows you to reset your password at any given time. Below is some details. \r
Username: $logged[username]
Pin Number: $current_user_pin \r
Please save this message. If you have gotten this message in error, please disregard this message.";
$checkuser = $logged[username];
$email = mysql_query("SELECT email FROM members WHERE username = '$checkuser' ORDER BY id DESC") or die (mysql_error());
$fetch = mysql_fetch_array($email);
mail($fetch['email'], "Subject: Pin Reminder", $mail, "From: $sitename Pin Reminder");
if(mail) {
echo "A email has been sent to $fetch[email]<BR>If you have yet to receive the message, then check your junk folder.";
}
break; |
any ideas?
| Code: | case 'send':
$pin = mysql_query("SELECT pincode FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchpin = mysql_fetch_assoc($pin);
$current_user_pin = $fetchpin['pincode'];
$mail = "You have selected a reminder from $sitename for your Pin Number. \r
A pin number allows you to reset your password at any given time. Below is some details. \r
Username: $logged['username']
Pin Number: $current_user_pin \r
Please save this message. If you have gotten this message in error, please disregard this message.";
$checkuser = $logged['username'];
$email = mysql_query("SELECT email FROM members WHERE username = '$checkuser' ORDER BY id DESC") or die (mysql_error());
$fetch = mysql_fetch_array($email);
mail($fetch['email'], "Subject: Pin Reminder", $mail, "From: $sitename Pin Reminder");
if(mail) {
echo "A email has been sent to $fetch['email']<BR>If you have yet to receive the message, then check your junk folder.";
}
break; |
Still nope, I noticed that you put ' and ' in the fetch part but when you do that I get:
| Code: | | Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/diablosb/domains/hotelmario.info/public_html/members/changepin.php on line 60 |
Maybe to help you out some more, I am trying to get the email to say the pin that they changed it to, heres what I get right now:
| Quote: | You have selected a reminder from Hotel Mario for your Pin Number.
A pin number allows you to reset your password at any given time. Below is some details.
Username: Diablosblizz
Pin Number:
Please save this message. If you have gotten this message in error, please disregard this message. |
See how it just blanks out the Pin Number, heres what it should look like:
| Quote: | You have selected a reminder from Hotel Mario for your Pin Number.
A pin number allows you to reset your password at any given time. Below is some details.
Username: Diablosblizz
Pin Number: 5643 (example)
Please save this message. If you have gotten this message in error, please disregard this message.
|
I did one test, and the $get_current_pin does not show up, not even on a page. So therefore the $get_current_pin does not work. I have tried changing
| Code: | $fetchpin = mysql_fetch_assoc($pin);
TO
$fetchpin = mysql_fetch_array($pin); |
Which never worked, I also tried removing the ' and ' from parts. I am still stumped, ???!
| fromegame wrote: | | Code: | case 'send':
$pin = mysql_query("SELECT pincode FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchpin = mysql_fetch_assoc($pin);
$current_user_pin = $fetchpin['pincode'];
$mail = "You have selected a reminder from $sitename for your Pin Number. \r
A pin number allows you to reset your password at any given time. Below is some details. \r
Username: $logged['username']
Pin Number: $current_user_pin \r
Please save this message. If you have gotten this message in error, please disregard this message.";
$checkuser = $logged['username'];
$email = mysql_query("SELECT email FROM members WHERE username = '$checkuser' ORDER BY id DESC") or die (mysql_error());
$fetch = mysql_fetch_array($email);
mail($fetch['email'], "Subject: Pin Reminder", $mail, "From: $sitename Pin Reminder");
if(mail) {
echo "A email has been sent to $fetch['email']<BR>If you have yet to receive the message, then check your junk folder.";
}
break; |
|
I see you get the username in the middle of the script:
| Code: |
$checkuser = $logged['username'];
|
But you need to do this before you use $checkuser in the first mysql query:
| Code: |
$pin = mysql_query("SELECT pincode FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
|
You could also combine the 2 queries:
| Code: |
$pin = mysql_query("SELECT pincode, email FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchpin = mysql_fetch_assoc($pin);
$current_user_pin = $fetchpin['pincode'];
$current_user_email= $fetchpin['email'];
|
Although I would leave that until you get the pincode extracting from the database first.
David.
Wow, that worked, and it was something so simple.
Thanks David.
|