$_POST['username'] NOT defined?!
What's wrong? It can't define what stands in this title, and the textbox's name sent HAS the name username
PHP Code:
<?php
include('config.php');
// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die('Cannot select database');
if ( isset( $_COOKIE['SundhedU'] ) && isset( $_COOKIE['SundhedP'] ) )
{
header( "Location: main.php" );
}
else
{
if($_POST['username'] {
//did they supply a password and username
$username=$_POST['username'];
$password=$_POST['password'];
if ($password==NULL) {
echo "<META HTTP-EQUIV='REFRESH' CONTENT='0;URL=index.php'>
";
}
else
{
$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['password'] != md5($password))
{
echo "<META HTTP-EQUIV='REFRESH' CONTENT='0;URL=index.php'>";
}
else
{
if (isset($_POST['husklogin']))
{
setcookie('SundhedU', $username, time() + 3600 * 24 * 365);
setcookie('SundhedP', md5($password), time() + 3600 * 24 * 365);
$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION["s_username"] = $row['username'];
header("Location: index.php");
}else{
$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION["s_username"] = $row['username'];
header("Location: index.php");
}
}
}
}
}
?>
Re: $_POST['username'] NOT defined?!
shouldn't
PHP Code:
if($_POST['username'] {
be
PHP Code:
if(isset($_POST['username'])) {
Re: $_POST['username'] NOT defined?!
As to do with the error message it means that you are trying to read a variable that has not been set. This is only a warning and does not affect your script, it will carry on as normal, you can change whether they are displayed or not via the php.ini file or by using error_reporting. But checking to seee if the variable has been set using isset() is much better.
Re: $_POST['username'] NOT defined?!
Ok great! But the string
PHP Code:
$username=$_POST['username'];
returns NULL
Re: $_POST['username'] NOT defined?!
Can you post your form code?
Re: $_POST['username'] NOT defined?!
PHP Code:
<form method='post' action='check.php'>
<left>Brugernavn
<input type='text' name='username'>
<br>
Kodeord
<input type='password' name='password'>
<input name='husklogin' type='checkbox' value='husklogin' checked>
Husk mig
<input name='submit' type='submit' value='Login'>
<br>
<br><center>
<a href='opretbruger.php'>.: Opret bruger her :.</a><br>
<a href='glemt.php'>.: Glemt login? :.</a></center></form>
Re: $_POST['username'] NOT defined?!
You could try using print_r($_POST);
to see what is getting passed through
or you could try
echo $HTTP_POST_VARS['username'];
or $_REQUEST['username];
just a thought
Re: $_POST['username'] NOT defined?!