-1

I have a code that when the user login his/her repcode will be seasion also or pass to the next page...but the user will only input username and password in the login page but in the next page his/her repcode is passed to ned page....can anyone help me...Im trying to figure it out it for 2 hours already...my head hurts...help me guys.

ex tb_name = 'id','name','username','password','repcode'

1st page:

<!DOCTYPE html>
<?php 
ob_start();
session_start();

include('include/connect.php');

?>

<html>
<head>
<title>test</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="hidden" name="repcode" value="<?php $repcode ?>">
<input type="submit" name="login" id="send" />
</form> 
</body>
</html>

<?php
// Inialize session
if(isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
// Include database connection settings
include('connection.php');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE username = '$username' and password = '$password'");

// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
$repcode1 = mysql_query("SELECT repcode FROM users WHERE username = '$username");
while($row = mysql_fetch_array($repcode1))
    {
        $repcode = $row['repcode'];                        
    } 
$_SESSION['repcode'] = $repcode;
// Jump to secured page
$stat="UPDATE users SET status='login'";
mysql_query($stat); 
header('Location: home2.php');
}
else {
}
}
?>

2nd page:

<!DOCTYPE html>
<?php 
ob_start();
session_start();
include('include/connect.php');
?>
<html>
<head>
<title>test</title>
</head>
<body>
<form method="get" >
  <input type="text" name="username" value="<?php echo $_SESSION['username']; ?> "/>
  <input type="text" name="repcode" value="<?php echo $_SESSION['repcode']; ?> "/>
</form></body>
</html>

I want to show the repcode of the user in the 2nd page but my current code it wont I need help please.

  • 2
    My head hurts trying to understand this! – Ryan Jan 23 '14 at 14:13
  • 1
    What is your actual question?? What do you expect to happen, whats in fact happening? – Steve Jan 23 '14 at 14:17
  • I want to show the user repcode in the 2nd page – user3227867 Jan 23 '14 at 14:18
  • Apart from the sql injection, deprecated functions, etc. **don't output anything to the browser before using `session_start();`** or `header()` or in this case `ob_start();`. See [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – jeroen Jan 23 '14 at 14:21

1 Answers1

0

You missed a single quote in the mysql query that gets the repcode, so change this:

$repcode1 = mysql_query("SELECT repcode FROM users WHERE username = '$username");

to this:

$repcode1 = mysql_query("SELECT repcode FROM users WHERE username = '$username'");

Also, mysql_* functions are deprecated. You should use mysqli_* functions instead.

elitechief21
  • 2,964
  • 1
  • 17
  • 15