Undefined variable problem
Moderator: General Moderators
Undefined variable problem
I uninstalled IIS and went to Apache2. I took the same code that had worked fine under IIS and now under Apache2 it will run but I get all these "Undefined variable..." errors. What am I doing wrong?
Thanks
Thanks
Code: Select all
<?php include("php_header.php"); ?>
//my db connection and session maintenance
<?php
if(isset($_SESSIONїuser_id])) {
?>
<a href="next.php">Next</a>
<?php
} elseif (is_null($_SESSIONїuser_id])) {
?>
<form name="login" action="login.php" method="POST">
<table>
<tr>
<td>Username: </td><td><input type="text" size="20" name="uname"></td>
</tr>
<tr>
<td>Password: </td><td><input type="password" size="20" name="pword"></td>
</tr>
</table>
<input type="Submit" value="Submit><input type="Reset" value="Reset">
</form>
<?php
}
?>Notice: Use of undefined constant user_id
--or--
Notice: Use of undefined index user_id
And I have tried both $_SESSION[user_id] and $_SESSION['user_id']
is should be $_SESSION['user_id'] no matter what.
Is $_SESSION['user_id'] always set when this script is run. If not that is why you get this error.
Change this line...
to...
You were checking to see if it was NULL, but if it hadn't been set at all, you will get a warning.
Mark
Is $_SESSION['user_id'] always set when this script is run. If not that is why you get this error.
Change this line...
Code: Select all
elseif (is_null($_SESSION['user_id'])) {Code: Select all
elseif (!isset($_SESSION['user_id'])) {Mark
you can achieve the same thing, but in a better way IMO
Mark
Code: Select all
<?php
include("php_header.php");
//my db connection and session maintenance
if(isset($_SESSION['user_id'])) {
?>
<a href="next.php">Next</a>
<?php
} else {
?>
<form name="login" action="login.php" method="POST">
<table>
<tr>
<td>Username: </td><td><input type="text" size="20" name="uname"></td>
</tr>
<tr>
<td>Password: </td><td><input type="password" size="20" name="pword"></td>
</tr>
</table>
<input type="Submit" value="Submit"><input type="Reset" value="Reset">
</form>
<?php
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK