user6546278 user6546278 - 7 months ago 22
PHP Question

php log in not working online but works perfectly fine offline

I have created a log in page in php ('login.php) that works fine offline. But when i take it online, the log in fails. However the other pages connect seamlessly to the same database from where I pull in the log in details. Here's the code on the log in page:

<link rel="stylesheet" href="css/admin_style.css">

<div id="login_style">
<div class="login_head">
<img src="images/admin_logo.png" alt="Parlour Products">
<img src="images/admin_panel.png" width="200" height="75" alt="Admin Panel" class="adminPanel">
<?php echo @$_GET['false_admin']; ?>
<?php echo @$_GET['logged_out']; ?>

<h1> Admin Section</h1><br>
<form method="post">
User Id: <input type="text" name="name" placeholder="Enter User ID" required="required" />
Password: <input type="password" name="pass" placeholder="Password" required="required" /><br><br>
<button type="submit" name="login">Log In</button>





include ("includes/db.php");


$name = mysql_real_escape_string($_POST['name']);
$pass = mysql_real_escape_string($_POST['pass']);

$sel_user = "select * from admin where admin_name='$email' AND admin_pass='$pass'";
$run_user = mysqli_query($con, $sel_user);

$check_user = mysqli_num_rows($run_user);

if($check_user==0 ){
echo "<script>alert('Login Failed. Please Try Again!')</script>";
else {
echo "<script>'index.php?logged_in=Sucessfully Logged In!','_self')</script>";



But every time I try to enter with the correct user name and password, I get the login error message. Initially I thought it was a database error, so I created this 'test.php' page with the following code:

<form action="test.php" method= "post" >

<td colspan="4" align="left"><h1>Insert New User</h1></td>
<td><input type="text" name="user_name"/></td>
<td><input type="text" name="user_pass"/></td>
<td><input type="submit" name="add_user" value="Add User" /></td>





$new_name = $_POST['user_name'];
$new_pass = $_POST['user_pass'];

$insert_user = "insert into admin (admin_name,admin_pass) values ('$new_name', '$new_pass')";

$run_user = mysqli_query($con,$insert_user);

echo "<script>alert('New User Added!')</script>";
echo "<script>'test.php','_self')</script>";



This 'test.php' page connects fine and even inserts the data into the table. The table structure is same both online and offline. Other user login pages are all working fine too!


First of all use the error reporting function when you're not sure of the error:

ini_set("display_errors", 1);

Probably the start session function is creating the problem here. try moving the


function to the top of the page, before any other text is outputted. Hopefully, this should solve it.