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!

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

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.

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

case 'Login':

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.