Hi,

The following is the error I'm getting
Notice: Undefined index: action in C:\bookstore\book_list.php on line 28
the code in red is generating error

book_list.php displays a list of books based on the users search criteria on index.php

A portion of index.php code

<table align=left width=30% height=20% border=0 cellpadding=3 cellspacing=10> <!--2a-->
<!-- bgcolor= "#c0c0c0"   -->
		<TR>
	  <td align="left" width=50px>
   <form name="frm" action="book_list.php" method=POST onSubmit="return validate_criteria(this)">
   <b>SEARCH</b> <br><select name="search_by">
    <option value="ISBN">ISBN</option>
    <option value="Title">Title</option>
    <option value="Author">Author</option>
    <option value="Publisher">Publisher</option>
    <option value="Subject" >Subject</option>
    </select><br><br>
   <input type="text" name="criteria" size=10>
<input type=SUBMIT value="OK">
    </form>
		<font><a href="book_list.php">Browse By Subject</a></td>
		</TR>
		<tr><td><br><br></td></tr>
		<tr><td><img src="stacked_books.gif" height="80"></td></tr>

	</table><!--2a-->

book_list.php code

<table>
<?php 

// This page will list all of the items 
// from the items table. Each item will have 
// a link to add it to the cart 
include("search.html");
include("db.php"); 

// Get a connection to the database 
//$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); 
$cxn = @ConnectToDb($server, $user, $pass, $database); 
//phpinfo();


//set_magic_quotes_runtime(1);

switch [COLOR="Red"]($_POST['action'])[/COLOR]{
default:
{create_select();
 $_SESSION[criteria]=FALSE;
 break;}

case "sel_subject":
{create_select_subject($_GET['subject']);
$_SESSION[criteria]=FALSE;
 break;}
}

Can someone help me?

    There is no $_POST array index coming from the form that is named "action". Do you have a form element named "action" somewhere in that form? If you do, it isn't being set when the form is submitted.

      Also note that you should never access external data without first verifying that it exists. Otherwise, you'll always generate the E_NOTICE level error. Instead, use [man]isset/man or [man]empty/man to verify that the variables exist. Common examples:

      if(isset($_POST['submit'])) {
          // process POST'ed data here
      } else {
          // display(?) form here - no data posted
      }

      or:

      // safely define $name to be POST'ed value or empty string
      $name = (isset($_POST['name']) ? $_POST['name'] : '');

        Hi Pikachu,

        I understand what ur telling and I kinda managed to solve that prob. But now I have another prob. book_list.php is not displaying the sql results. It is fetching the correct data from the database based on the search criteria, however it is not displaying it. The following is my code. The code in red is not displaying the query results.

        print '<table class="book_list" width=100%>
        
        <tr  bgcolor="red" align=center>
        					<th>Book Title</th>
        					<th>Author</th>
        					<th>Price</th>
        					<th>Add?</th>
        </tr>';
        
        while($row = mysql_fetch_array($result)) 
        { 
        
        [COLOR="Red"]print
        '<tr> 
        <td width="30%"  height="25"> 
        <?php echo $row["title"]; ?>
        </td> 
        <td width="25%" height="25"> 
        <?php echo $row["author"]; ?> 
        </td> 
        <td width="35%" height="25" align="right"> 
        $<?php echo $row["price"]; ?> 
        </td> 
        <td width="20%" height="25"> 
        <a href="cart.php?action=add_item&isbn=<?php echo $row["ISBN"]; ?>&qty=1">Add To Cart</a> 
        </td> 
        </tr> 
        <tr> 
        <td colspan="4"> 
        <hr size="1" NOSHADE> 
        </td> 
        </tr> [/COLOR]';
        }//END OF WHILE LOOP 
        
        print '</table>'; 

        can u please help me?

        thank you.

          If you have another problem, it would be better to start a new thread to ask it. Doing so will reduce confusion from readers about what the problem under discussion is, and will make it easier for people searching for threads discussing a problem similar to theirs to find them.

            Write a Reply...