...

View Full Version : Form not passing variables to PHP via. post



reashlin
03-15-2007, 07:49 PM
OK

strange problem here. I am going to post 4 pages that I am using in a webpage under development and hopefully people can work their way around them.

But basically loginform.php is not passing anything to logincheck.php even though the form is set method="post". You may notice on the last page some output where i have commented out the header re-direct. This is so that i can see what the variables are. They are coming out as blank. I have tried force using _REQUEST instead of _POST on this last page and this still does not find any results.

I have tried googling the problem and some results seem to imply it could be a problem with my apache setup, is this likely?

Sorry for how much code this is but i thought it best to give you everything.


<?php

session_start();

include_once 'included/doctype.php';

echo '<html>';

include_once 'included/head.php';

echo '<body>';

include_once 'included/div/banner.php';

include_once 'included/div/menu.php';

include_once 'included/div/login.php'; // ***This is the important bit***

include_once 'included/div/logged_in_menu.php';

include_once 'included/div/logo.php';

if ($_GET['page'] == null) // If the page attribute is not set.
{
$page = index;
}
else if (file_exists("included/main/" .$_GET['page'] . ".php")) // Only allow the attribute to be set if the file exists.
{
$page = $_GET['page'];
}
else // If the file does not exist or the page attribute is not set then default to index.php
{
$page = index;
}

include_once "included/main/$page.php";

echo '</body>';

echo '</html>';
?>


<div id="login">

<?php
if(!isset($_SESSION['username']))
{
include 'included/loginform.php'; // ***IMPORTANT***
}
else
{
$username = $_SESSION['username'];
$account_type = $_SESSION['account_type'];
echo "$username is logged in with $account_type privileges.";

echo '<br />';
echo '<input type="button" value="Log Out" onclick="Javascript: document.location=\'included/logout.php\'" />';

}
?>
</div>




<h3>LOG IN</h3>
<form name="login" method="post" action="included/logincheck.php"> <!-- This does say post -->
<p>Name:<br />
<input id="username" type="text" maxlength="10" />
<br />
Password:<br />
<input id="password" type="password" maxlength="255" />
<br />
<br />
<input type="submit" id="submit" value="login" />
</p>
</form>

<?
$check = $_GET['login'];

if ($check == invalid)
{
echo "Incorrect Username or Password!";
echo '<br />';
echo $_GET['username'] . $_GET['password'];
}
else
{
}
?>


<?php
session_start();

include_once 'db_connection_open.php';

$username = $_POST['username'];
$password = $_POST['password'];

$sql = "SELECT *
FROM USERS
WHERE USERNAME = '$username'
AND PASSWORD = '$password'";

$result = mysql_query($sql, $connection)
or die ("Couldn't perform query $sql <br />" . mysql_error());

$row = mysql_fetch_array($result);

if ($row != null)
{
$_SESSION['username'] = $row['USERNAME'];
$_SESSION['account_type'] = $row['ACCOUNT_TYPE'];
header("Location: ../index.php");
exit();
}
else
{
echo "Username: ".$username;
echo "<br />Pass: ".$password;
//header("Location: ../index.php?login=invalid&username='$username'&password='$password'");
//exit();
}

include_once 'db_connection_close.php';
?>

Inigoesdr
03-15-2007, 08:03 PM
You have to name the input fields
<input type="text" name="username" ..

Nightfire
03-15-2007, 09:05 PM
Also, you should add quotes around invalid here.

if ($check == 'invalid')

reashlin
03-15-2007, 11:59 PM
cheers guys...

i thought id="" was the same as name=""



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum