|
-
Apr 19th, 2006, 05:15 AM
#1
Thread Starter
Addicted Member
$_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");
}
}
}
}
}
?>
-
Apr 19th, 2006, 05:45 AM
#2
<?="Moderator"?>
Re: $_POST['username'] NOT defined?!
shouldn't
PHP Code:
if($_POST['username'] {
be
PHP Code:
if(isset($_POST['username'])) {
-
Apr 19th, 2006, 05:47 AM
#3
<?="Moderator"?>
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.
-
Apr 19th, 2006, 06:08 AM
#4
Thread Starter
Addicted Member
Re: $_POST['username'] NOT defined?!
Ok great! But the string
PHP Code:
$username=$_POST['username'];
returns NULL
-
Apr 19th, 2006, 06:51 AM
#5
Re: $_POST['username'] NOT defined?!
Can you post your form code?
-
Apr 19th, 2006, 06:53 AM
#6
Thread Starter
Addicted Member
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>
-
Apr 19th, 2006, 09:00 PM
#7
Conquistador
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
-
Apr 20th, 2006, 02:20 AM
#8
Thread Starter
Addicted Member
Re: $_POST['username'] NOT defined?!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|