Hi, i am still new to php..
I had a index.php which has a login form inside. THis form will then send to check_login.php to check if the username exist or not? The problem is, i could not display the login error message in the same page as index.php.
Here is my check_login php code
<?php
session_start();
?>
<?php
$host= "localhost"; // Host name
$username= "root"; // Mysql username
$db_name="mysecureemail"; // Database name
$tbl_name="member"; // Table name
// Connect to server and select databse.
$conn= mysql_connect("$host", "$username")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$email=$_POST['email'];
$Upass=$_POST['Upass'];
// To protect MySQL injection
$email = stripslashes($email);
$Upass = stripslashes($Upass);
$email = mysql_real_escape_string($email);
$Upass = mysql_real_escape_string($Upass);
$sql= sprintf("SELECT * FROM $tbl_name WHERE email='$email' and Upass='$Upass'");
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register("email");
session_register("Upass");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
how to display the error message in the index.php instead off appearing in check_login.php
Displaying Login Error in the login page
Moderator: General Moderators
Re: Displaying Login Error in the login page
When posting code in the forum, place it between BBCode tags.
[/code]
can be condensed into
which is better because $email and $Upass are never contaminated.
This
should be
or
The only reasons to do this
are
Otherwise,
Edit: This post was recovered from search engine cache.
Code: Select all
[php][/php] or [code=php]ThisPHP Manual wrote:session_register() -- This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
Code: Select all
$email = $_POST['email'];
$Upass = $_POST['Upass'];
$email = stripslashes($email);
$Upass = stripslashes($Upass);
$email = mysql_real_escape_string($email);
$Upass = mysql_real_escape_string($Upass);Code: Select all
$email = mysql_real_escape_string(stripslashes($_POST['email']));
$Upass = mysql_real_escape_string(stripslashes($_POST['Upass']));This
Code: Select all
$sql = sprintf("SELECT * FROM $tbl_name WHERE email='$email' and Upass='$Upass'");Code: Select all
$sql = sprintf("SELECT * FROM %s WHERE email='%s' and Upass='%s'", $tbl_name, $email, $Upass);Code: Select all
$sql = "SELECT * FROM $tbl_name WHERE email='$email' and Upass='$Upass'";Code: Select all
$y = "$x";- you suspect that $x might be a number and you want $y to be a string.
- you are going to add more to the string, as in these examples:
Code: Select all
$y = "$x\n";
$y = "<p>$x</p>";Code: Select all
$y = $x;
some_function($x);Redesign the relationship of your pages so that check_login.php is included in index.php. Store the error message in a variable and echo it on index.php.xiaomahe wrote:how to display the error message in the index.php instead off appearing in check_login.php
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:59 pm, edited 1 time in total.
Re: Displaying Login Error in the login page
hai, thnks for replying.. i forget to check this post, because i am so busy doing this project..
i am still learning PHP and thanks for the answer as well as the tips..
i am still learning PHP and thanks for the answer as well as the tips..
Re: Displaying Login Error in the login page
Hi,
You can also do this without session and other things, follow this
login.html
The place in html where you want to display the error message
in your login_check.php
Hope this helps
Warning: I am new to php, cross check my code!
You can also do this without session and other things, follow this
login.html
Code: Select all
<?php
$urlValue = $_GET['code'];
if($urlValue = "password"){
$display = "Password wrong";
}else if ($urlValue = "username"){
$display = "User name invalid";
}else{
$display = "";
}
?>
Code: Select all
<?php $display ?>Code: Select all
//When the userid is wrong
header("Location:http://www.x.com/index.html?code=username");
// When the password is wrong
header("Location:http://www.x.com/index.html?code=password");
Warning: I am new to php, cross check my code!