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'] = 'do.not.reply@email.com';
		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
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'] = 'do.not.reply@email.com';
		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

Link to comment
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'] = 'do.not.reply@email.com';
		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?

Link to comment
Share on other sites

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("name@domain.com", $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?

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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