• (2 Pages)
  • +
  • 1
  • 2

Text Based Mafia Game || Register and Forgot pass Part 2. Creating the Register and Forgot pass on our Text Based Game Rate Topic: -----

#16 Shadowing  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 26-November 11

Posted 27 November 2011 - 05:41 AM

I got stuck on the register.php
just gives me a white page with no errors. just a blank white page.

This is what I have for the code

<?php include_once("connect.php"); ?>
<? 
if (isset($_POST['Register'])) {


if(strlen($_POST['Username'])<3 || strlen($_POST['Username'])>32)
	{ // This check the characters of the username and it makes sure if it is longer that 3 letters.
		echo 'Your name must be between 3 and 32 characters!';
	
	}else{
	
	if(empty($_POST['Password'])){ // This checks the password field to see if it is empty
		echo 'You need to select a password!';
	}else{
	
	if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['Username']))
	{// this checks the user for any symbols space etc .You can remove this is you choose
		echo 'Your name contains invalid characters!';
	}else{
	
	if(!checkEmail($_POST['Email']))
	{ // this is one of the functions we added on the function page. for this to work make sure the function is required on this page
		echo 'Your email is not valid!';
	}else{
	

if(empty($_POST['Agree'])){ // Check if the Checkbox is checked to agree with the terms of services
echo "You need to accept the Terms & conditions  in order to sign up.!";
}else{


// this check and makes sure that their are no duplication with the email
$sql = "SELECT id FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
	  
if($m_count >= "1"){
echo 'This email has already been used.!';
}else{


// this makes sure that all the uses that sign up have their own names
$sql = "SELECT id FROM users WHERE name='".mysql_real_escape_string($_POST['Username'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
	  
if($m_count >= "1"){
echo 'This name has already been used.!';
}else{

$password = md5($_POST['Password']); // this is a md5 hash. its encrypt your password so it isnt easily hackable



// The id is blank because it is an auto_increment  which mean it will auto add a value to every user and the are all different. this is mainly so we dont have dupilcate. 
													
$sql = "INSERT INTO users SET id = '', name = '".$_POST['Username']."' , password= '$password', mail= '".$_POST["Email"]."'";
$res = mysql_query($sql);

$to = $_POST['Email'];
    $from = "no-reply@Game.co.uk";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear ".$_POST['Username'].", <br>
    <center>
Your Username: ".$_POST['Username']."<p>

Your Password: ".$_POST['Password']."<p>

	  <p>
	  <font size=3> You recived this mail because someone used this mail to sign up to a game</font>
  </body>
</html>";
   
    $headers  = "From: Game Registration Details <no-reply@Game.co.uk>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

echo "".$_POST['Username'].", Welcome to the game.";
}}}
						}

					}
			}
	}
}

?>

Was This Post Helpful? 0
  • +
  • -

#17 Shadowing  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 26-November 11

Posted 27 November 2011 - 05:48 AM

And this is my functions.php code

<?php include_once("connect.php"); ?> 
<?php require 'functions.php'; ?> 
<?php
function checkEmail($str) // This function is going to help us filter out bad email from the good one and it makes sure the email enter is in the format of as@as.com
{
	return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}


function send_mail($from,$to,$subject,$body)// this is a send email function that will help us send email to the registered users.
{
	$headers = '';
	$headers .= "From: $from\n";
	$headers .= "Reply-to: $from\n";
	$headers .= "Return-Path: $from\n";
	$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Date: " . date('r', time()) . "\n";

	mail($to,$subject,$body,$headers);
}
?>

Was This Post Helpful? 0
  • +
  • -

#18 Shadowing  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 26-November 11

Posted 29 November 2011 - 02:31 AM

Alright I solved my problem
my problems was understanding the steps when replacing code on top of code and stuff.

Im going to post what the register, Functions and Lost_Pass file should look like when you are done.
Even though my mail settings isnt set up on my apache server atm everything seems to work besides the mail error I get cause of that. Also im still not sure if I need to add <?php include_once("connect.php"); ?> on the functions page or the Lost_Pass page???? and the very last code that says need to be added i wasnt sure to add that to the functions page or the Lost_pass page???? When i do set my mailing up on my server i'll come back and repost here to let everyone know if this was truely the correct way to do each 3 files.

<?php include_once("connect.php"); ?>

<? require 'functions.php'; ?>

<html>
<body>

<? 
if (isset($_POST['Register'])) {


if(strlen($_POST['Username'])<3 || strlen($_POST['Username'])>32)
	{ // This check the characters of the username and it makes sure if it is longer that 3 letters.
		echo 'Your name must be between 3 and 32 characters!';
	
	}else{
	
	if(empty($_POST['Password'])){ // This checks the password field to see if it is empty
		echo 'You need to select a password!';
	}else{
	
	if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['Username']))
	{// this checks the user for any symbols space etc .You can remove this is you choose
		echo 'Your name contains invalid characters!';
	}else{
	
	if(!checkEmail($_POST['Email']))
	{ // this is one of the functions we added on the function page. for this to work make sure the function is required on this page
		echo 'Your email is not valid!';
	}else{
	

if(empty($_POST['Agree'])){ // Check if the Checkbox is checked to agree with the terms of services
echo "You need to accept the Terms & conditions  in order to sign up.!";
}else{


// this check and makes sure that their are no duplication with the email
$sql = "SELECT id FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
	  
if($m_count >= "1"){
echo 'This email has already been used.!';
}else{


// this makes sure that all the uses that sign up have their own names
$sql = "SELECT id FROM users WHERE name='".mysql_real_escape_string($_POST['Username'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
	  
if($m_count >= "1"){
echo 'This name has already been used.!';
}else{

$password = md5($_POST['Password']); // this is a md5 hash. its encrypt your password so it isnt easily hackable



// The id is blank because it is an auto_increment  which mean it will auto add a value to every user and the are all different. this is mainly so we dont have dupilcate. 
													
$sql = "INSERT INTO users SET id = '', name = '".$_POST['Username']."' , password= '$password', mail= '".$_POST["Email"]."'";
$res = mysql_query($sql);

$to = $_POST['Email'];
    $from = "no-reply@Game.co.uk";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear ".$_POST['Username'].", <br>
    <center>
Your Username: ".$_POST['Username']."<p>

Your Password: ".$_POST['Password']."<p>

	  <p>
	  <font size=3> You recived this mail because someone used this mail to sign up to a game</font>
  </body>
</html>";
   
    $headers  = "From: Game Registration Details <no-reply@Game.co.uk>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

echo "".$_POST['Username'].", Welcome to the game.";
}}}
						}

					}
			}
	}
}

?>

<form method="post" >
  <center>
    <h1><strong>Register</strong></h1>
    <p>UserName: 
      <input type="text" name="Username" id="Username">
    </p>
    <p>Password:
      <input type="password" name="Password" id="Password">
    </p>
    <p>Email: 
      <input type="text" name="Email" id="Email">
    </p>
    <p>
      <input type="checkbox" name="Agree" id="Agree"> Agree to Term of Services
      <br />
<input type="submit" name="Register" id="Register" value="Register">
    </p>
  </center>
</form>

</body>
</html>



<?
function checkEmail($str) // This function is going to help us filter out bad email from the good one and it makes sure the email enter is in the format of as@as.com
{
	return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}


function send_mail($from,$to,$subject,$body)// this is a send email function that will help us send email to the registered users.
{
	$headers = '';
	$headers .= "From: $from\n";
	$headers .= "Reply-to: $from\n";
	$headers .= "Return-Path: $from\n";
	$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Date: " . date('r', time()) . "\n";

	mail($to,$subject,$body,$headers);
}
?>



<html>
<body>

<? 
if (isset($_POST['Register'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
}
		

?>

<? 
if (isset($_POST['Send'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password

$nsql = "SELECT * FROM login WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->pass);
$mail = htmlspecialchars($row->email);

	
	
if((empty($_POST['Email']))){ // if the email field is empty there will be an error

		echo 'You one field empty.';
	}else{
		
	
	  if(empty($name)){ // there is no name with the entered email
		echo 'Invalid information.';
	}else{
	
	  if($_POST['Email'] != $mail){
			echo 'Invalid information.'; // if their is no match in the email
	}else{
	
	if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
		echo 'Your email is not valid!';
	}else{
		
	$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'") 
or die(mysql_error());	

			$to = $_POST['Email'];
    $from = "no-reply@Game.co.uk";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear $name, <br>
    <center>
Your Username: $name <p>

Your Password: $password <p>

  </body>
</html>";
   
    $headers  = "From: Game Lost Details <no-reply@Game.co.uk>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

			echo 'We sent you an email with your Details!';
		
	}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.		

?>

<form method="post" >
  <center>
    <h1><strong>Lost Password</strong></h1>
    <p>Email: 
      <input type="text" name="Email" id="Email">
      <br>
<input type="submit" name="Send" id="Send" value="Send">
    </p>
</center>
</form>

</body>
</html/>

Was This Post Helpful? 0
  • +
  • -

#19 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 101
  • Joined: 29-July 09

Posted 31 December 2011 - 07:19 AM

View Postkris123, on 24 September 2011 - 08:33 AM, said:

here

if(empty($name)){ if // there is no name with the entered email
echo 'Invalid information.';


and this happens Parse error: syntax error, unexpected T_ECHO, expecting '(' in /home/mafiaass/public_html/lost_pass.php on line 45 this is line 45 help me pls



post/attach the whole page of your code.

View PostShadowing, on 29 November 2011 - 09:31 AM, said:

Alright I solved my problem
my problems was understanding the steps when replacing code on top of code and stuff.

Im going to post what the register, Functions and Lost_Pass file should look like when you are done.
Even though my mail settings isnt set up on my apache server atm everything seems to work besides the mail error I get cause of that. Also im still not sure if I need to add <?php include_once("connect.php"); ?> on the functions page or the Lost_Pass page???? and the very last code that says need to be added i wasnt sure to add that to the functions page or the Lost_pass page???? When i do set my mailing up on my server i'll come back and repost here to let everyone know if this was truely the correct way to do each 3 files.

<?php include_once("connect.php"); ?>

<? require 'functions.php'; ?>

<html>
<body>

<? 
if (isset($_POST['Register'])) {


if(strlen($_POST['Username'])<3 || strlen($_POST['Username'])>32)
	{ // This check the characters of the username and it makes sure if it is longer that 3 letters.
		echo 'Your name must be between 3 and 32 characters!';
	
	}else{
	
	if(empty($_POST['Password'])){ // This checks the password field to see if it is empty
		echo 'You need to select a password!';
	}else{
	
	if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['Username']))
	{// this checks the user for any symbols space etc .You can remove this is you choose
		echo 'Your name contains invalid characters!';
	}else{
	
	if(!checkEmail($_POST['Email']))
	{ // this is one of the functions we added on the function page. for this to work make sure the function is required on this page
		echo 'Your email is not valid!';
	}else{
	

if(empty($_POST['Agree'])){ // Check if the Checkbox is checked to agree with the terms of services
echo "You need to accept the Terms & conditions  in order to sign up.!";
}else{


// this check and makes sure that their are no duplication with the email
$sql = "SELECT id FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
	  
if($m_count >= "1"){
echo 'This email has already been used.!';
}else{


// this makes sure that all the uses that sign up have their own names
$sql = "SELECT id FROM users WHERE name='".mysql_real_escape_string($_POST['Username'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
	  
if($m_count >= "1"){
echo 'This name has already been used.!';
}else{

$password = md5($_POST['Password']); // this is a md5 hash. its encrypt your password so it isnt easily hackable



// The id is blank because it is an auto_increment  which mean it will auto add a value to every user and the are all different. this is mainly so we dont have dupilcate. 
													
$sql = "INSERT INTO users SET id = '', name = '".$_POST['Username']."' , password= '$password', mail= '".$_POST["Email"]."'";
$res = mysql_query($sql);

$to = $_POST['Email'];
    $from = "no-reply@Game.co.uk";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear ".$_POST['Username'].", <br>
    <center>
Your Username: ".$_POST['Username']."<p>

Your Password: ".$_POST['Password']."<p>

	  <p>
	  <font size=3> You recived this mail because someone used this mail to sign up to a game</font>
  </body>
</html>";
   
    $headers  = "From: Game Registration Details <no-reply@Game.co.uk>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

echo "".$_POST['Username'].", Welcome to the game.";
}}}
						}

					}
			}
	}
}

?>

<form method="post" >
  <center>
    <h1><strong>Register</strong></h1>
    <p>UserName: 
      <input type="text" name="Username" id="Username">
    </p>
    <p>Password:
      <input type="password" name="Password" id="Password">
    </p>
    <p>Email: 
      <input type="text" name="Email" id="Email">
    </p>
    <p>
      <input type="checkbox" name="Agree" id="Agree"> Agree to Term of Services
      <br />
<input type="submit" name="Register" id="Register" value="Register">
    </p>
  </center>
</form>

</body>
</html>



<?
function checkEmail($str) // This function is going to help us filter out bad email from the good one and it makes sure the email enter is in the format of as@as.com
{
	return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}


function send_mail($from,$to,$subject,$body)// this is a send email function that will help us send email to the registered users.
{
	$headers = '';
	$headers .= "From: $from\n";
	$headers .= "Reply-to: $from\n";
	$headers .= "Return-Path: $from\n";
	$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Date: " . date('r', time()) . "\n";

	mail($to,$subject,$body,$headers);
}
?>



<html>
<body>

<? 
if (isset($_POST['Register'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
}
		

?>

<? 
if (isset($_POST['Send'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password

$nsql = "SELECT * FROM login WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->pass);
$mail = htmlspecialchars($row->email);

	
	
if((empty($_POST['Email']))){ // if the email field is empty there will be an error

		echo 'You one field empty.';
	}else{
		
	
	  if(empty($name)){ // there is no name with the entered email
		echo 'Invalid information.';
	}else{
	
	  if($_POST['Email'] != $mail){
			echo 'Invalid information.'; // if their is no match in the email
	}else{
	
	if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
		echo 'Your email is not valid!';
	}else{
		
	$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'") 
or die(mysql_error());	

			$to = $_POST['Email'];
    $from = "no-reply@Game.co.uk";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear $name, <br>
    <center>
Your Username: $name <p>

Your Password: $password <p>

  </body>
</html>";
   
    $headers  = "From: Game Lost Details <no-reply@Game.co.uk>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

			echo 'We sent you an email with your Details!';
		
	}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.		

?>

<form method="post" >
  <center>
    <h1><strong>Lost Password</strong></h1>
    <p>Email: 
      <input type="text" name="Email" id="Email">
      <br>
<input type="submit" name="Send" id="Send" value="Send">
    </p>
</center>
</form>

</body>
</html/>



if you put the connect.php file on the functions.php page then you need to require the functions.php page on top of the lost_pass.php.
Was This Post Helpful? 0
  • +
  • -

#20 Phantom Coder  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 13
  • Joined: 26-April 09

Posted 05 February 2012 - 10:21 PM

First I like to say thanks for the great tutorial Keep up the great work.
the error everyone seems to be getting is because of a typo on that line the "if" after the { should be behind the comment tags // it should be part of the comment.

also i came across a couple of other errors

$nsql = "SELECT * FROM login WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->pass);
$mail = htmlspecialchars($row->email);

it should be

$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);

I'm pretty new to coding PHP and with the directions the author is giving I can follow this pretty well even with the errors. I kind found the 4 error enjoyable got me to really looking through the code I learned a lot from it because of the errors. I actually had to go through the code and read it instead of just cutting and pasting and having it work,

This post has been edited by modi123_1: 05 February 2012 - 11:06 PM
Reason for edit:: cleared up an excessively long quote

Was This Post Helpful? 1
  • +
  • -

#21 apx900  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 18-February 12

Posted 23 February 2012 - 06:24 PM

Hello :)
let me just say that this is an excellent set of tutorials. i've managed to follow this right the way through and solve any of my mistakes on my own, until now that is. i'm getting the error as seen in the attached picture.


Posted Image

and as you can see i am able to connect and add information to the table.


Posted Image

and finally below is what i have for my Lost_Pass.php
its fairly late at night i will try and find out where i went wrong again tomorrow morning.
in the mean time any help that anyone can offer will be greatly appriciated

<?php include_once("connect.php"); ?>
<html>
    <head><title></title></head>
    <body>

        <?php
        if (isset($_POST['Send'])) {

            $password = substr(md5($_SERVER['REMOTE_ADDR'] . microtime() . rand(1, 100000)), 0, 6);
            // Generate a random password

            $nsql = "SELECT * FROM users WHERE mail='" . mysql_real_escape_string($_POST['Email']) . "'";
            $query = mysql_query($nsql) or die(mysql_error());
            $row = mysql_fetch_object($query);
            $name = htmlspecialchars($row->name);
            $pass = htmlspecialchars($row->pass);  //this is where the error starts
            $mail = htmlspecialchars($row->email); 

            if ((empty($_POST['Email']))) { // if the email field is empty there will be an error
                echo 'You one field empty.';
            } else {


                if (empty($name)) {//if there is no name with the entered email
                    echo 'Invalid information.';
                } else {

                    if ($_POST['Email'] != $mail) {
                        echo 'Invalid information.'; // if their is no match in the email
                    } else {

                        if (!checkEmail($_POST['Email'])) { // the checkEmail function we have in our function that saves us time and sapce
                            echo 'Your email is not valid!';
                        } else {

                            $result = mysql_query("UPDATE users SET password='$password' WHERE name='" . mysql_real_escape_string($name) . "'")
                                    or die(mysql_error());

                            $to = $_POST['Email'];
                            $from = "no-reply@Game.co.uk";
                            $subject = "Registration - Your Registration Details";

                            $message = "<html>
                                        <body background=\"#4B4B4B\">
                                        <h1>Game Registration Details</h1>
                                        Dear $name, <br>
                                        <center>
                                        Your Username: $name <p>
                                        Your Password: $password <p>
                                        </body>
                                        </html>";

                            $headers = "From: Game Lost Details <no-reply@Game.co.uk>\r\n";
                            $headers .= "Content-type: text/html\r\n";

                            mail($to, $subject, $message, $headers);

                            echo 'An email with you new password has been dispatched';
                        }
                    }
                }// check if name is unused.
            }// check if accepted to the tos.
        }// name check.
// if post register.		
        ?>






        <form method="post" >
            <center>
                <h1><strong>Lost Password</strong></h1>
                <p>Email: 
                    <input type="text" name="Email" id="Email">
                    <br>
                    <input type="submit" name="Send" id="Send" value="Send">
                </p>
            </center>
        </form>

    </body>
</html>

Was This Post Helpful? 0
  • +
  • -

#22 apx900  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 18-February 12

Posted 27 February 2012 - 05:48 AM

View PostPhantom Coder, on 05 February 2012 - 10:21 PM, said:

First I like to say thanks for the great tutorial Keep up the great work.
the error everyone seems to be getting is because of a typo on that line the "if" after the { should be behind the comment tags // it should be part of the comment.

also i came across a couple of other errors

$nsql = "SELECT * FROM login WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->pass);
$mail = htmlspecialchars($row->email);

it should be

$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);

I'm pretty new to coding PHP and with the directions the author is giving I can follow this pretty well even with the errors. I kind found the 4 error enjoyable got me to really looking through the code I learned a lot from it because of the errors. I actually had to go through the code and read it instead of just cutting and pasting and having it work,



Thank you!! that fixed my problem :) :genius:
Was This Post Helpful? 0
  • +
  • -

#23 Cydex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-April 13

Posted 23 April 2013 - 01:40 PM

i got stuck Lost_Pass.php
i did everything and i try to use it and wrote ,my mail and i got this massage We sent you an email with your Details! , but i never get the Details !
This My Code Please any help
<?php include_once("connect.php"); ?>
<html>
<body>
<? require 'functions.php'; ?>
<? 
if (isset($_POST['Register'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
}
		

?>

<? 
if (isset($_POST['Send'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);

	
	
if((empty($_POST['Email']))){ // if the email field is empty there will be an error

		echo 'You one field empty.';
	}else{
		
	
	  if(empty($name)){ // there is no name with the entered email
		echo 'Invalid information.';
	}else{
	
	  if($_POST['Email'] != $mail){
			echo 'Invalid information.'; // if their is no match in the email
	}else{
	
	if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
		echo 'Your email is not valid!';
	}else{
		
	$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'") 
or die(mysql_error());	

			$to = $_POST['Email'];
    $from = "owner@df.w-sro.com";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear $name, <br>
    <center>
Your Username: $name <p>

Your Password: $password <p>

  </body>
</html>";
   
    $headers  = "From: Game Lost Details <owner@df.w-sro.com>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

			echo 'We sent you an email with your Details!';
		
	}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.		

?>

<form method="post" >
  <center>
    <h1><strong>Lost Password</strong></h1>
    <p>Email: 
      <input type="text" name="Email" id="Email">
      <br>
<input type="submit" name="Send" id="Send" value="Send">
    </p>
</center>
</form>

</body>
</html/>

Was This Post Helpful? 0
  • +
  • -

#24 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 101
  • Joined: 29-July 09

Posted 25 April 2013 - 04:26 AM

View PostCydex, on 23 April 2013 - 09:40 PM, said:

i got stuck Lost_Pass.php
i did everything and i try to use it and wrote ,my mail and i got this massage We sent you an email with your Details! , but i never get the Details !
This My Code Please any help
<?php include_once("connect.php"); ?>
<html>
<body>
<? require 'functions.php'; ?>
<? 
if (isset($_POST['Register'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
}
		

?>

<? 
if (isset($_POST['Send'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);

	
	
if((empty($_POST['Email']))){ // if the email field is empty there will be an error

		echo 'You one field empty.';
	}else{
		
	
	  if(empty($name)){ // there is no name with the entered email
		echo 'Invalid information.';
	}else{
	
	  if($_POST['Email'] != $mail){
			echo 'Invalid information.'; // if their is no match in the email
	}else{
	
	if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
		echo 'Your email is not valid!';
	}else{
		
	$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'") 
or die(mysql_error());	

			$to = $_POST['Email'];
    $from = "owner@df.w-sro.com";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear $name, <br>
    <center>
Your Username: $name <p>

Your Password: $password <p>

  </body>
</html>";
   
    $headers  = "From: Game Lost Details <owner@df.w-sro.com>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

			echo 'We sent you an email with your Details!';
		
	}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.		

?>

<form method="post" >
  <center>
    <h1><strong>Lost Password</strong></h1>
    <p>Email: 
      <input type="text" name="Email" id="Email">
      <br>
<input type="submit" name="Send" id="Send" value="Send">
    </p>
</center>
</form>

</body>
</html/>


Try using my send_mail function, also are the details getting saved on to the database? try making the login.
Was This Post Helpful? 0
  • +
  • -

#25 Cydex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-April 13

Posted 25 April 2013 - 10:06 AM

View PostDenis1, on 25 April 2013 - 04:26 AM, said:

View PostCydex, on 23 April 2013 - 09:40 PM, said:

i got stuck Lost_Pass.php
i did everything and i try to use it and wrote ,my mail and i got this massage We sent you an email with your Details! , but i never get the Details !
This My Code Please any help
<?php include_once("connect.php"); ?>
<html>
<body>
<? require 'functions.php'; ?>
<? 
if (isset($_POST['Register'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
}
		

?>

<? 
if (isset($_POST['Send'])) {

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password
$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);

	
	
if((empty($_POST['Email']))){ // if the email field is empty there will be an error

		echo 'You one field empty.';
	}else{
		
	
	  if(empty($name)){ // there is no name with the entered email
		echo 'Invalid information.';
	}else{
	
	  if($_POST['Email'] != $mail){
			echo 'Invalid information.'; // if their is no match in the email
	}else{
	
	if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
		echo 'Your email is not valid!';
	}else{
		
	$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'") 
or die(mysql_error());	

			$to = $_POST['Email'];
    $from = "owner@df.w-sro.com";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear $name, <br>
    <center>
Your Username: $name <p>

Your Password: $password <p>

  </body>
</html>";
   
    $headers  = "From: Game Lost Details <owner@df.w-sro.com>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

			echo 'We sent you an email with your Details!';
		
	}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.		

?>

<form method="post" >
  <center>
    <h1><strong>Lost Password</strong></h1>
    <p>Email: 
      <input type="text" name="Email" id="Email">
      <br>
<input type="submit" name="Send" id="Send" value="Send">
    </p>
</center>
</form>

</body>
</html/>


Try using my send_mail function, also are the details getting saved on to the database? try making the login.

Ok bro i will try and tell you if i stuck again
Was This Post Helpful? 0
  • +
  • -

#26 Cydex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-April 13

Posted 28 April 2013 - 05:47 PM

Still Stuck Here Bro :(
Still Get this "We sent you an email with your Details!"
and the pass didn't send :(
and i made the index.php to login and try to login and yeah i can login
so any help please ?

<? 
function checkEmail($str) // This function is going to help us filter out bad email from the good one and it makes sure the email enter is in the format of as@as.com
{
	return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
if (isset($_POST['Send'])){

$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
		// Generate a random password

$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);

if((empty($_POST['Email']))){ // if the email field is empty there will be an error

		echo 'You one field empty.';
	}else{
		
	
	  if(empty($name)){ // there is no name with the entered email
		echo 'Invalid information.';
	}else{
	
	  if($_POST['Email'] != $mail){
			echo 'Invalid information.'; // if their is no match in the email
	}else{
	
	if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
		echo 'Your email is not valid!';
	}else{
		
	$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'") 
or die(mysql_error());	

			$to = $_POST['Email'];
    $from = "owner@df.w-sro.com";
    $subject = "Registration - Your Registration Details";

    $message = "<html>
   <body background=\"#4B4B4B\">
   <h1>Game Registration Details</h1>
   Dear $name, <br>
    <center>
Your Username: $name <p>

Your Password: $password <p>

  </body>
</html>";
   
    $headers  = "From: Game Lost Details <no-reply@Game.co.uk>\r\n";
    $headers .= "Content-type: text/html\r\n";

	mail($to, $subject, $message, $headers);             

			echo 'We sent you an email with your Details!';
		
	}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.		

?>



And this My page Lost_Pass.php
<?php include_once("connect.php"); ?>
<? require 'functions.php'; ?>
<html>
<body>
<form method="post" >
  <center>
    <h1><strong>Lost Password</strong></h1>
    <p>Email: 
      <input type="text" name="Email" id="Email">
      <br>
<input type="submit" name="Send" id="Send" value="Send">
    </p>
</center>
</form>

</body>
</html/>


Was This Post Helpful? 0
  • +
  • -

#27 Shadowing  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 26-November 11

Posted 28 April 2013 - 07:42 PM

Cydex do you have error reporting turned on? Also do you have a email server installed?
Was This Post Helpful? 0
  • +
  • -

#28 Cydex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-April 13

Posted 29 April 2013 - 04:04 PM

View PostShadowing, on 28 April 2013 - 07:42 PM, said:

Cydex do you have error reporting turned on? Also do you have a email server installed?


i didn't get any error, just the password never go to the mail, and i have website and everything is ok, only the password :(
Was This Post Helpful? 0
  • +
  • -

#29 Shadowing  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 34
  • Joined: 26-November 11

Posted 30 April 2013 - 01:58 AM

So you are getting mail right? Just the password isn't in the email? Or you are not getting any emails at all?

Start first by doing echo "$password";
At the bottom of the page. Make sure the variable $password isn't empty.


If you are not getting emails then do a test on a blank page like this mail("your email","test","test","test");

To see if you get a email



Let me know your results

This post has been edited by Shadowing: 30 April 2013 - 02:02 AM

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2