Jump to content

does nothing?


Porkie

Recommended Posts

<?php 
ini_set ("display_errors", "1");
error_reporting(E_ALL);
// Include the database connection file.
include("connection.php");
// Check if a person has clicked on submit.
if(isset($_POST['submit'])) { 
// Check if a person has filled every form.
if(empty($_POST['username']))
 echo "You Havent Filled In The Username Field.";
elseif(empty($_POST['password']))
 echo "You Havent Filled In The Password Field.";
    elseif(empty($_POST['password2']))
 echo "You Havent Filled In The Confirm Password Field.";
elseif(empty($_POST['email']))
     echo "You Havent Filled In the Email Field.";          
                exit;
}
// Create variables from each $_POST.
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$account = $_POST['account'];

// Now, compare passwords and check if they're the same.

if($password != $password2) {
	// If the passwords are NOT the same. Again display an error message and redirect.
	echo "Sorry, Your Two Passwords Dont Match Up.";
                exit;
}
// Secure the password using an md5 hash.
$password = md5($password);

// Create a variable containing the SQL query.
$query = "INSERT INTO `Members` (username, password, email, account) 
                      VALUES ('$username', '$password', '$email', '$account')";
// Perform the SQL query on the database.
$result = mysql_query($query);
// If the query failed, display an error.
if(!$result) { 
                // The dot seperates PHP code and plain text.
	echo "Your query failed. " . mysql_error();
} else {
	// Display a success message!
	echo "Welcome " . $username . " You are now registered";
}

?>

 

after this ends it doesnt do anything except show a white screen i think its something wrong with the check the password field however iam confused?

 

any help?

 

cheers

Link to comment
Share on other sites

You closed the

 

if(isset($_POST['submit'])) {

 

to early.  The close should be at the end of the script (see below).  Also, you need to clean your variables to protect from sql injection.

 

<?php 
ini_set ("display_errors", "1");
error_reporting(E_ALL);
// Include the database connection file.
include("connection.php");
// Check if a person has clicked on submit.
if(isset($_POST['submit'])) { 
   // Check if a person has filled every form.
   if(empty($_POST['username'])){
    die("You Havent Filled In The Username Field.");
   }elseif(empty($_POST['password'])){
    die("You Havent Filled In The Password Field.");
    }elseif(empty($_POST['password2'])){
    die("You Havent Filled In The Confirm Password Field.");
   }elseif(empty($_POST['email'])){
     die("You Havent Filled In the Email Field.");
   }

   // Create variables from each $_POST.
   $username = mysql_real_escape_string($_POST['username']);
   $password = mysql_real_escape_string($_POST['password']);
   $password2 = mysql_real_escape_string($_POST['password2']);
   $email = mysql_real_escape_string($_POST['email']);
   $account = mysql_real_escape_string($_POST['account']);

   // Now, compare passwords and check if they're the same.

   if($password != $password2) {
      // If the passwords are NOT the same. Again display an error message and redirect.
      echo "Sorry, Your Two Passwords Dont Match Up.";
                exit;
   }
   // Secure the password using an md5 hash.
   $password = md5($password);

   // Create a variable containing the SQL query.
   $query = "INSERT INTO `Members` (username, password, email, account) 
                      VALUES ('$username', '$password', '$email', '$account')";
   // Perform the SQL query on the database.
   $result = mysql_query($query);
   // If the query failed, display an error.
   if(!$result) { 
                // The dot seperates PHP code and plain text.
      echo "Your query failed. " . mysql_error();
   } else {
      // Display a success message!
      echo "Welcome " . $username . " You are now registered";
   }

}else{
die("No post variables set");
}

?>

Link to comment
Share on other sites

your mysql_query($query);

 

should be

 

mysql_query($query,$con);

 

(or whatever $connection you used)

 

the "mysql_query($query,$con);" with the $con isn't always necessary.  It depends on what's contained within your connection.php file.

Link to comment
Share on other sites

your mysql_query($query);

 

should be

 

mysql_query($query,$con);

 

(or whatever $connection you used)

 

the "mysql_query($query,$con);" with the $con isn't always necessary.  It depends on what's contained within your connection.php file.

 

Oh, thanks for that.

Link to comment
Share on other sites

your mysql_query($query);

 

should be

 

mysql_query($query,$con);

 

(or whatever $connection you used)

 

the "mysql_query($query,$con);" with the $con isn't always necessary.  It depends on what's contained within your connection.php file.

 

Oh, thanks for that.

 

Read the manual for more information - mysql_query.

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.