Jump to content

[SOLVED] login.php form validation error


MasterACE14

Recommended Posts

Morning Everyone,

 

I have a homepage called home.php with a username, email and password input box, that form is then submitted to login.php which checks whether anything was entered into the username box, and their is another validation which checks whether the id of the entered username exists, and if it doesnt it displays an error. both validations are working fine. But when I enter a correct account, it goes to login.php and shows a blank page, instead of automatically redirecting to base.php . Could someone please help, I need this fixed urgently!

 

here's login.php:

<?php  // Login the Player

// Process the POST variables
$username = $_POST["username"];

if (empty($username)) {

// Tell them to enter a correct username, password and e-mail
echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br>
<input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";

die();

};

// Setup the session variables
$_SESSION['username'] = $username;

// Connect to database ready to match the usernames, then switch over to match the ID
$rs = mysql_connect( "localhost", "ace_ACE", "*****" );
$rs = mysql_select_db( "ace_cf" );

// SQL query for all entries in descending order
$sql = "SELECT `id` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1";
$rs = mysql_query( $sql ) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());

// This gets the data from the result resource
//$query = mysql_result($rs,0,0);

while($row = mysql_fetch_assoc($rs)){
      if(isset($row['id'])){return $row['id'];}
}

// Put the players ID into a variable
$player_id = $query;

if (empty($player_id)) {

// Tell them to enter a correct username, password and e-mail
echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br>
<input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";

die();

};

// Put the players ID variable into a session variable
$_SESSION['playerid'] = $player_id;

if (!empty($player_id)) {

// Start the output buffer so we dont create any errors with headers
ob_start();

// Automatically redirect the player to the base page
header("Location: index.php?page=base");

// End ob
ob_end_flush();

};

?>

 

Regards ACE

Link to comment
Share on other sites

hey just wanna diagnose the problem so i just poped an echo in the code below if the echo dose work the header throws a wobbly if the echo dose not work we know the ass has fallen out of the IF statement above it so test it and let me know

 

 

<?php  // Login the Player

// Process the POST variables
$username = $_POST["username"];

if (empty($username)) {

// Tell them to enter a correct username, password and e-mail
echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br>
<input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";

die();

};

// Setup the session variables
$_SESSION['username'] = $username;

// Connect to database ready to match the usernames, then switch over to match the ID
$rs = mysql_connect( "localhost", "ace_ACE", "*****" );
$rs = mysql_select_db( "ace_cf" );

// SQL query for all entries in descending order
$sql = "SELECT `id` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1";
$rs = mysql_query( $sql ) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());

// This gets the data from the result resource
//$query = mysql_result($rs,0,0);

while($row = mysql_fetch_assoc($rs)){
      if(isset($row['id'])){return $row['id'];}
}

// Put the players ID into a variable
$player_id = $query;

if (empty($player_id)) {

// Tell them to enter a correct username, password and e-mail
echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br>
<input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";

die();

};

// Put the players ID variable into a session variable
$_SESSION['playerid'] = $player_id;

if (!empty($player_id)) {
echo "look at me i'm inside an if statement";
// Start the output buffer so we dont create any errors with headers
ob_start();

// Automatically redirect the player to the base page
header("Location: index.php?page=base");

// End ob
ob_end_flush();

};

?>

 

Link to comment
Share on other sites

You logic is a pretty well all over the place. Try...

 

<?php

session_start();

$username = $_POST["username"];
if (empty($username)) {
 echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br>
   <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";
 die();
}

mysql_connect( "localhost", "ace_ACE", "*****" );
mysql_select_db( "ace_cf" );
$sql = "SELECT `id` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1";
if ($rs = mysql_query( $sql )) {
 if (mysql_num_rows($rs)) {
   $row = mysql_fetch_assoc($rs);
   $_SESSION['username'] = $username;
   $_SESSION['playerid'] = $row['id'];
   header("Location: index.php?page=base");
 } else {
   echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br>
           <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>";
           die();
 }
} else {
 die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error();
}

?>

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.