PHP wont header ! redirect.
#1

PHP код:
<?php
 
require('config.php');
 
session_start();
 
// If form submitted, insert values into the database.
 
if (isset($_POST['password'])){
 
$username $_POST['username'];
 
$password $_POST['password'];
 
$username stripslashes($username);
 
$username mysql_real_escape_string($username);
 
$password stripslashes($password);
 
$password mysql_real_escape_string($password);
 
//Checking is user existing in the database or not
 
$query "SELECT * FROM `users` WHERE username='$username' and password='".sha1($password)."'";
 
$result mysql_query($query) or die(mysql_error());
 
$rows mysql_num_rows($result);
 if(
$rows==1){
 
$_SESSION['username'] = $username;
 
header("Location: profile.php"); // Redirect user to index.php
 
}else{
 echo 
"random text";
 }
 }else{
 }
?>
It just refreshes the login page even if i write correct username and password

PHP код:
form action="" method="post" name="login">
<
input type="text" name="username" placeholder="Username" required />
<
input type="password" name="password" placeholder="Password" required />
<
input type="image" src="https://i.imgur.com/uVoJ8Kl.pngg" />
</
form
Reply
#2

someone help/
Reply
#3

I don't know about php that much, but this part kind of bugging me:
PHP код:
if($rows==1){ 
 
$_SESSION['username'] = $username
 
header("Location: profile.php"); // Redirect user to index.php 
 
}else{ 
 echo 
"random text"
 } 
 }else{ 
 } 
An if statement can only have one else.
Reply
#4

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
I don't know about php that much, but this part kind of bugging me:
PHP код:
if($rows==1){ 
 
$_SESSION['username'] = $username
 
header("Location: profile.php"); // Redirect user to index.php 
 
}else{ 
 echo 
"random text"
 } 
 }else{ 
 } 
An if statement can only have one else.
No, Nothing wrong he isnt using it twice at all. It is the else from if isset.


Add obstart(); on top and exit() after the header
Also Why are you copying vars from the post method? ThAts not even necessary.
And i Dont see an action at your form. It must refer to the page that obtains the code u are using to Check for the username and pw
Reply
#5

header redirect method doesn't work if something has already been sent to the output stream, make sure there is no echo statement or HTML code above the header() line, also make sure that there is no faulty code above header() line which can potentially cause an error or warning message to be echoed and use exit() function after using header() function to avoid extra processing.
Reply
#6

I did all of them, still doesn't work.

<?php is the first code of my script.

Added the

PHP код:
<form action="profile.php" method="post" name="login">
<
input type="text" name="username" placeholder="Username" required />
<
input type="password" name="password" placeholder="Password" required />
<
input type="submit" src="https://i.imgur.com/uVoJ8Kl.png" />
</
form
But now profile.php it shows blank. If I remove profile.php from the action it shows fine (if i enter manually, my problem is that login buton won't send me to profile.php)
Reply
#7

up up
Reply
#8

Your action shouldnt be profile.php. this is where you get redirected after login. Save this as login.php
Код:
<?php*

*require('config.php');*
*session_start();*
*//*If*form*submitted,*insert*values*into*the*database.*
*if*(isset($_POST['password'])){*
*$username*=*$_POST['username'];*
*$password*=*$_POST['password'];*
*$username*=*stripslashes($username);*
*$username*=*mysql_real_escape_string($username);*
*$password*=*stripslashes($password);*
*$password*=*mysql_real_escape_string($password);*
*//Checking*is*user*existing*in*the*database*or*not*
*$query*=*"SELECT***FROM*`users`*WHERE*username='$username'*and*password='".sha1($password)."'";*
*$result*=*mysql_query($query)*or*die(mysql_error());*
*$rows*=*mysql_num_rows($result);*
*if($rows==1){*
*$_SESSION['username']*=*$username;*
*header("Location:*profile.php");*//*Redirect*user*to*index.php*
*}else{*
*echo*"random*text";*
*}*
*}else{*
 echo 'form*action="login.php"*method="post"*name="login">*
<input*type="text"*name="username"*placeholder="Username"*required*/>*
<input*type="password"*name="password"*placeholder="Password"*required*/>*
<input*type="image"*src="https://i.imgur.com/uVoJ8Kl.pngg"*/>*
</form>**';
*}*
?>
Also stop bumping after short amount of time. There is a 24 hours bump rule

Edit : lmao my tablet replaced all spaces with stars weird
Reply
#9

Still doesnt work
Reply
#10

Quote:
Originally Posted by Zeus666
Посмотреть сообщение
Still doesnt work
What does not work exactly? please be more specific. By the way are u using error_reporting(E_ALL); ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)