I am using a very simple user login system (http://php.codenewbie.com/articles/php/1482/Login_With_Sessions-Page_1.html) everything works great... until I try to insert data into my database while logged in. Once I do this I get logged out immediately and doesn't insert the data.
Here is my auth.php page
<?
// Login & Session example by sde
// auth.php
// start session
session_start();
// convert username and password from _POST or _SESSION
if($_POST){
$_SESSION['username']=$_POST["username"];
$_SESSION['password']=$_POST["password"];
}
// query for a user/pass match
//include("global/db.inc.php");
$result=mysql_query("select * from users WHERE username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "' AND status='active'");
// retrieve number of rows resulted
$num=mysql_num_rows($result);
// print login form and exit if failed.
if($num < 1){?>
<form method="POST" action="index.php">
<table id="login">
<tr>
<td width="25%" class="loginheader">Username:</td>
<td width="5%" class="loginheader"> </td>
<td width="70%" class="loginheader"><input type="text" name="username" class="textbox" size="10"></td>
</tr>
<tr>
<td class="loginheader">Password:</td>
<td class="loginheader"> </td>
<td class="loginheader"><input type="password" name="password" class="textbox" size="10"></td>
</tr>
</table>
<input type="submit" class="button" value="Login">
</form>
Not registered yet?<br />
Go <a href="register.php">here</a> to do so.
<?
exit;
}
?>
Here is my add page
<?
if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF'])) {
echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
exit;
}
?>
<table id="sample">
<tr>
<td colspan="3" class="toprow">Add Game</td>
</tr>
<td class="data">
<script language="javascript" type="text/javascript" src="js/datetimepicker.js"></script>
<script>
function changeSeasonType(seasontype)
{
window.location="?act=addgame&seasontype=" + seasontype;
}
</script>
<?
if (isset($_POST['away'])) {
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO schedule VALUES (
'$away',
'$awayscore',
'$home',
'$homescore',
'$seasontype',
'$gametype',
'$gameday',
'$time'
)";
mysql_query($query);
echo "Game Added";
mysql_close();
}
?>
<form method="post" action="index.php?act=addgame" target="_self">
<table id="simple">
<tr>
<td nowrap='nowrap' colspan="1" ></td>
<td nowrap='nowrap' colspan="3" ></td>
</tr>
<tr>
<td nowrap='nowrap' colspan="4" ></td>
</tr>
</table>
<table id="simple">
<tr>
<td><div class="plaintext">Season Type:</div></td>
<td>
<?
$getlist = mysql_query("SELECT * FROM seasontype ORDER BY 'seasontype' ASC");
echo " <select name=\"seasontype\" tabindex=\"\" value=\"$seasontype\" onChange='changeSeasonType(this.value)'>\n";
echo ' <option value='.$seasontype.'>'.$seasontype.'</option>';
echo "<option value=''>Select One</option>";
while ($row = mysql_fetch_array($getlist)) {
echo ' <option value="'.$row["seasontype"].'">'.$row["seasontype"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td><div class="plaintext">Game Type:</div></td>
<td>
<?
$getlist = mysql_query("SELECT * FROM gametype WHERE type = '$seasontype' ORDER BY 'order' ASC");
echo " <select name=\"gametype\" tabindex=\"\" value=\"$gametype\">\n";
echo "<option value=''>Select One</option>";
while ($row = mysql_fetch_array($getlist)) {
echo ' <option value="'.$row["game"].'">'.$row["game"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td nowrap='nowrap' colspan="2" class="tdTitle"><br/></td>
</tr>
<tr>
<td>Away Team:</td>
<td>
<?
$getlist = mysql_query("SELECT * FROM teams ORDER BY team ASC");
echo " <select name=\"away\" tabindex=\"\" value=\"$away\">\n";
echo "<option value=''>Select One</option>";
while ($row = mysql_fetch_array($getlist)) {
echo ' <option value="'.$row["team"].'">'.$row["team"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td>Home Team:</td>
<td>
<?
$getlist = mysql_query("SELECT * FROM teams ORDER BY team ASC");
echo " <select name=\"home\" tabindex=\"\" value=\"$home\">\n";
echo "<option value=''>Select One</option>";
while ($row = mysql_fetch_array($getlist)) {
echo ' <option value="'.$row["team"].'">'.$row["team"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td nowrap='nowrap' colspan="2" class="tdTitle"><br/></td>
</tr>
<tr>
<td><div class="plaintext">Game Day:</div></td>
<td>
<a href="javascript:NewCal('gameday','yyyymmdd')"><img src="imgs/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> <input name="gameday" id="gameday" type="text" size="8" value="<? print date("Y-m-j"); ?>">
</td>
</tr>
<tr>
<td><div class="plaintext">Game Time:</div></td>
<td>
<div class="plaintext"><?php $start = strtotime('06:00');
$end = strtotime('21:00');
echo '<select name="time">';
for ($i = $start; $i <= $end; $i += 300)
{
echo '<option>' . date('H:i', $i);
}
echo '</select>'; ?></div>
</td>
</tr>
<tr>
<td><br/><input type="submit" name="SubmitButton" value="Submit"><input type="reset" value="Reset" name="B2"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
Here is my index page
<?
include("global/db.inc.php");
include("auth.php");
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<table id="container">
<tr>
<td colspan="3">
<?
include_once("global/AFC.php");
?>
</td>
</tr>
<tr>
<td colspan="3">
<?
include_once("global/NFC.php");
?>
</td>
</tr>
<tr>
<td class="left" valign="top">
<?
include_once("global/leftsidebar.inc.php");
?>
</td>
<td class="center" valign="top">
<?
// START MAIN CONTENT
if(isset($_GET["act"])){
switch ($_GET["act"]) {
case "addgame":
include_once("admin/addgame.inc.php");
break;
case "settings":
include_once("admin/settings.inc.php");
break;
case "login":
include_once("auth.php");
break;
case "logout":
include_once("logout.php");
break;
case "userupdate":
include_once("season/userupdate.inc.php");
break;
case "viewschedule":
include_once("season/NSW.inc.php");
break;
}
} else {
include_once("season/NSW.inc.php");
}
?>
</td>
<td class="right" valign="top">
<?
include_once("global/rightsidebar.inc.php");
?>
</td>
</tr>
</table>
Any ideas why this is doing that?