blackwolf23 Posted June 5, 2007 Share Posted June 5, 2007 Hello, I'm having trouble querying my database for the email address of a specific user and using that email address in the php mail function to send the user their new password. The below code keeps generating the error 'Call to undefined function mysqli_fetch_object() in Functions.php on line 138' WHich I can't seem to figure out why(I am still new to php). function email_passwd($Username,$test) { //Get the email address of the user from the db $conn = connect(); $query = "SELECT Email FROM Users WHERE Username = '".$Username."'"; $result = mysql_query($query); $row = mysqli_fetch_object($query); //Email the user $to = '$row->Email'; $subject = 'Password Reset'; $message = "Your password has been reset to $test"; mail($to, $subject, $message); } Quote Link to comment Share on other sites More sharing options...
squiggerz Posted June 5, 2007 Share Posted June 5, 2007 Have you tried using mysql_fetch_assoc instead of _fetch_object? If all you are fetching is an email addy, I dont see why that wouldnt work. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 5, 2007 Share Posted June 5, 2007 Try this: $row = mysql_fetch_object($result); Quote Link to comment Share on other sites More sharing options...
squiggerz Posted June 5, 2007 Share Posted June 5, 2007 *points up* This is why he has 3 stars, I have 1. lol, I didnt even notice he was fetching his query instead of the resulting variable. Good eye Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 5, 2007 Share Posted June 5, 2007 Thanks mate. Coding is like that some time a simple and little error we did not see. Quote Link to comment Share on other sites More sharing options...
blackwolf23 Posted June 5, 2007 Author Share Posted June 5, 2007 Thanks for solving my problem but for some reason I still have not recieved an email yet. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 5, 2007 Share Posted June 5, 2007 I think if i am right here a mail function has 4 parameters. $headers = 'From: ME <support@domain.com>' . "\r\n" . 'Cc: cccc@yahoo.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion() ."\r\n". 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $to = '$row->Email'; $subject = 'Password Reset'; $message = "Your password has been reset to $test"; mail($to, $subject, $message,$headers); Quote Link to comment Share on other sites More sharing options...
blackwolf23 Posted June 5, 2007 Author Share Posted June 5, 2007 Mail has 3 required parameters from what I have read and I can only get this code to work if I enter an email address in the $To variable. I'm guessing something is wrong with this line $to = '$row->Email'; Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 5, 2007 Share Posted June 5, 2007 ok it depends on u how many parameter u want to pass u r right 3 r required other is optional, But if u mention it ur mails will not go to junk folder or spam folder. now come to ur point. $to = '$row->Email'; should be: $to= $row->Email; Confirm Email field in db, is Email not email. Quote Link to comment Share on other sites More sharing options...
blackwolf23 Posted June 5, 2007 Author Share Posted June 5, 2007 Another person suggested I try the following which fixed the problem. $row = mysql_fetch_assoc($result); $to = $row['Email']; Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 5, 2007 Share Posted June 5, 2007 This will also fix ur problem. $to= $row->Email; Quote Link to comment Share on other sites More sharing options...
blackwolf23 Posted June 5, 2007 Author Share Posted June 5, 2007 Ok,I might test that to. Thankyou for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.