1,105,386 Community Members

Undefined index notice

Member Avatar
tripwirekse
Newbie Poster
3 posts since Oct 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello,
I'm very new to PHP and am trying to code a basic content management system. Every time I try and test my login I get a blank page and the same notice pops up:

Notice: Undefined index: action in test\newsite\transact-user.php on line 10

I've searched high and low for answers and have tried several: changed my error_reporting, tried declaring the problem index, etc. Here is the problem code:

<?php
require_once 'conn.php';
require_once 'http.php';

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting (E_ALL);

if (!isset($_REQUEST['action'])) {
  switch ($_REQUEST['action']) {
    case 'Login':
      if (isset($_POST['username'])
          and isset($_POST['password']))
      {
        $sql = "SELECT user_id, access_level,first_name " .
               "FROM user_info " .
               "WHERE username='" . $_POST['username'] . "' " .
               "AND password='" . $_POST['password'] . "'";
        $result = mysql_query($sql, $conn)
          or die('Could not look up user information; ' . 
                 mysql_error());

        if ($row = mysql_fetch_array($result)) {
          session_start();
          $_SESSION['user_id'] = $row['user_id'];
          $_SESSION['access_level'] = $row['access_level'];
          $_SESSION['first_name'] = $row['first_name'];
        }
      }
	  redirect('/index.php');
      break;

My login area looks like this:

<div id="navright">
<?php if (!isset($_SESSION['user_id'])){
echo '<form method="post" action="transact-user.php">';
echo '<fieldset>';
echo '<label for="username">USERNAME: </label><input type="text" id="username" name="username" class="formInput" /><br />';
echo '<label for="password">PASSWORD: </label><input type="password" id="password" name="password" class="formInput" /><br />';
echo '<input id="submit" name="action" type="submit" value="LOGIN" class="submitB" />';
echo '</fieldset>';
echo '</form>';
} ?>
</div>

The weird thing is that this worked before on several occasions, but then it all of a sudden quit working and leaves me with a blank page. Any help is very much appreciated!

Member Avatar
tripwirekse
Newbie Poster
3 posts since Oct 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Update:
Now it is not giving me any errors or notices, just a blank page

Member Avatar
pritaeas
mod_pritaeas
11,315 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 
if (!isset($_REQUEST['action'])) 
{  
  switch ($_REQUEST['action']) 
  {
    ...

This is weird. First you test if action IS NOT SET. Next you see which value it has. The answer is: none. You should probably remove the ! (not) from the if statement.

Member Avatar
tripwirekse
Newbie Poster
3 posts since Oct 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I've tried it both ways and they both yield the same result. A blank page.

Member Avatar
pritaeas
mod_pritaeas
11,315 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 
case 'Login':

is case-sensitive. Are you sure that Login is passed to your URL (login is not the same, neither is LOGIN) ?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: