Jump to content

Problems with mysql_query & SELECT


giannis_athens

Recommended Posts

Hello everyone.... iam a newbie in your forum and a starter in PHP programming.

To be straight i want to grab registered user's email from email table in MySQL and use it to email him/her when he/she changes password

i have made this script but it doesnt work  :shrug:

 

$_result =  mysql_query("SELECT `email` FROM  `members` WHERE `name` = '$_user'")or die (mysql_error());

$info = mysql_query( $_result );

 

$info = $to

$subject="Change password";

$message="You have changed your password to: $_newpass";

 

$m=mail($to, $subject, $message);

 

Ofcourse all the connection to my database its ok and my php code thats changes the password in db works fine!!! :)

The problem is that i want to email the user (informing his/her password change) without asking his/her email address,

but by grabbing it from MySQL database

Is there a possible solution for that? :confused:

 

Link to comment
https://forums.phpfreaks.com/topic/180483-problems-with-mysql_query-select/
Share on other sites

<?php
//ok - here, you've made a query. The result of this query is assigned to the variable $result.
//This is your result set. i.e. everything that was returned. I noticed that you didn't include the
//code where you assigned something to the variable $_user? Why not just call it $user?
$user = $_user; //just me assigning whatever was in $_user to $user.
$result =  mysql_query("SELECT `email` FROM  `members` WHERE `name` = '$user'")or die (mysql_error());

//here's your big problem. what you're doing here is trying to query mysql without a query. The 
//function that you should be using here is mysql_fetch_row()
//$info = mysql_query($result); so I commented that part out
$info = mysql_fetch_row($result); //fetching your database row from the result that mysql returned

//another problem lies here. you have it the wrong way around. you're assigning a blank variable
//to $info, meaning you're overwriting everything you've got so far
//$info = $to;  //so I commented that bit out and put this in
$to = $info[0]; 
$subject="Change password";
$message="You have changed your password to: $_newpass";

$m=mail($to, $subject, $message);

//That's about as much as I can help you with
?>

Thanx anyway for your help!!!!!!!!Honestly you are very kind!!!!

To be more more specific here is my all code:

<?php
$_user = $_POST['_user'];
$_oldpass = $_POST['_oldpass'];
$_newpass = $_POST['_newpass'];
$_txtfromchbox = $_POST['_txtfromchbox'];

$link = mysql_connect('localhost', 'user', 'password');
if (!$link) 
{
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('my_data_base', $link);
if (!$db_selected)
{
    die ('Can\'t use users: ' . mysql_error());
}
$SQL="SELECT `name`, `pass` ,`email` FROM `my_data_base`.`members`";
$result = mysql_query($SQL);
if (!$result) 
{
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
$_member=false;

while ($row = mysql_fetch_assoc($result)) 
{
if($row['pass']==$_oldpass)
{
	$_member=true;
	break;	
}
    
}
if ($_member==true) 
{
$sql = "UPDATE `my_data_base`.`members` SET `pass` = '$_newpass' WHERE `members`.`name` = '$_user' LIMIT 1;";
$result = mysql_query($sql);
echo ("ok");

if ($_txtfromchbox=="okay")
{
	$_result =  mysql_query("SELECT `email` FROM  `members` WHERE `name` = '$_user'")or die (mysql_error());

	$info = mysql_query( $_result );

	$info = $to
	$subject="Change password";
	$message="Change password into $_newpass";
	$m=mail($to, $subject, $message);
}
}
else
{
echo "not";
}
mysql_free_result($result);
mysql_close($link);
?> 

So the part of changing passord ..it works...(with some changes in this form, but works!)  but i have put a checkbox into my flash page, in case the user wants to have an email with his new password.

otherwise it will simply only changes the password.

This is my all form...chack if there is something that you see there!

Thank you very much for your help!

Archived

This topic is now archived and is closed to further replies.

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