Jump to content

[SOLVED] Hmm... Something's not right in this;


adamjones

Recommended Posts

I have this code, which should connect to my database, grab the e-mail for the username given, and mail them a message, which will have a link in for them to reset their password;

 

<?php

session_start();


require_once('config.php');


$errmsg_arr = array();


$errflag = false;


$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}


$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}


function clean($str) {
	$str = @trim($str);
	if(get_magic_quotes_gpc()) {
		$str = stripslashes($str);
	}
	return mysql_real_escape_string($str);
}

$username = clean($_POST['username']);


if($username == '') {
	$errmsg_arr[] = 'Invalid username';
	$errflag = true;
}


if($errflag) {
	$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
	session_write_close();
	header("location: login_failure.php");
	exit();
}

$qry="SELECT * FROM members WHERE username='$myusername'";
$result=mysql_query($qry);


if($result) {
	if(mysql_num_rows($result) == 1) {

		session_regenerate_id();
		$member = mysql_fetch_assoc($result);
		$_SESSION['email'] = $member['email'];
		$_SESSION['subject'] = 'Password Request';
		$_SESSION['message'] = 'Link to reset pass here';
		$_SESSION['from'] = '[email protected]';
		session_write_close();
	}

mail("$email", $subject, $message, $from);

?>
<?php
header("location: index.php");
	exit();
	?>

 

But I get this error;

 

"Parse error: syntax error, unexpected $end in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 74"

 

It should register the email, subject and message, and then send an email to them? Correct?

 

Cheers,

Adam.

Link to comment
https://forums.phpfreaks.com/topic/145668-solved-hmm-somethings-not-right-in-this/
Share on other sites

found it: 

<?php 

if($result) {//1 open
	if(mysql_num_rows($result) == 1) {//2open

		session_regenerate_id();
		$member = mysql_fetch_assoc($result);
		$_SESSION['email'] = $member['email'];
		$_SESSION['subject'] = 'Password Request';
		$_SESSION['message'] = 'Link to reset pass here';
		$_SESSION['from'] = '[email protected]';
		session_write_close();
	}//1 close were is 2 close??

mail("$email", $subject, $message, $from);?>

 

look at your braces '}' in the code i posted i put comments next to them

found it: 

<?php 

if($result) {//1 open
	if(mysql_num_rows($result) == 1) {//2open

		session_regenerate_id();
		$member = mysql_fetch_assoc($result);
		$_SESSION['email'] = $member['email'];
		$_SESSION['subject'] = 'Password Request';
		$_SESSION['message'] = 'Link to reset pass here';
		$_SESSION['from'] = '[email protected]';
		session_write_close();
	}//1 close were is 2 close??

mail("$email", $subject, $message, $from);?>

 

look at your braces '}' in the code i posted i put comments next to them

 

Ok, thanks :)

 

That fixed it, however, it's not sending the message for some reason?

are you getting an error?if not add this at the top of the page :

 

ini_set('error_reporting', E_ALL);

 

P.s why do you have $email inside quotes " " ?

 

if you dont get an error message after adding that then im not to sure.

are you getting an error?if not add this at the top of the page :

 

ini_set('error_reporting', E_ALL);

 

P.s why do you have $email inside quotes " " ?

 

if you dont get an error message after adding that then im not to sure.

 

Because the format for it should be;

 

mail("[email protected]", $subject, $message, $from);

 

So, I grabbed the email from the database of the user, set it to register as a variable, and placed it in there.

 

Oh dear... These are the errors;

 

"Notice: Undefined variable: email in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56

 

Notice: Undefined variable: subject in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56

 

Notice: Undefined variable: message in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56

 

Notice: Undefined variable: from in /home/wowdream/public_html/designbyfreedom/habhub/passwordrequest.php on line 56"

 

I have defined them though, right?

 

 

 

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.