Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2006, 11:22 AM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch 5 - form4.php loads itself blank

When I click "Search" or "Add" the form4.php loads itself. This happens only when I check "Movie" in the radio buttons. "Actor" and "Director" seem to work fine.

Somebody has already posted something similar, but he didn´t put the code for us to see and the other guy who answered couldn´t help. So please can someone help on it finally?

I would really appreciate if you post your codes if they have worked with you.

Please help me!!!!

CODES BELOW:

startform.php:

<html>
<head>
<TITLE>Multipurpose Form</TITLE>
</head>
<body>
<FORM action="form4.php?step=1" method="post">
<table border=0 width="750" cellspacing=1 cellpadding=3 bgcolor="#353535" align="center">
     <tr>
         <td bgcolor="#ffffff" width="30%">
            Name
         </td>
         <td bgcolor="#ffffff" width="70%">
            <INPUT type="TEXT" name="Name">
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff">
            Item Type
         </td>
         <td bgcolor="#ffffff">
            <INPUT type="radio" name="type" value="Movie:Movie" CHECKED>
            Movie<BR>
            <INPUT type="radio" name="type" value="Person:Actor">
            Actor<BR>
            <INPUT type="radio" name="type" value="Person:Director">
            Director<BR>
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff">
            Movie type (if applicable)
         </td>
         <td bgcolor="#ffffff">
            <SELECT name="MovieType">
             <option value="" SELECTED>Movie type...</option>
             <option value="Action">Action</option>
             <option value="Drama">Drama</option>
             <option value="Comedy">Comedy</option>
             <option value="Sci-Fi">Sci-Fi</option>
             <option value="War">War</option>
             <option value="Other">Other...</option>
            </SELECT>
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff" width="50%">
            Display Debug Dump
         </td>
         <td bgcolor="#ffffff" width="50%">
            <INPUT type="checkbox" name="Debug" CHECKED>
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff" colspan=2 align="center">
            <INPUT type="SUBMIT" name="Submit" value="Search">
            <INPUT type="SUBMIT" name="Submit" value="Add">
         </td>
     </tr>
</table>
</FORM>
</body>
</html>


form4.php

<?php
// Debug info Display
function debugDisplay(){
?>
<PRE>
$_POST
<?php
print_r($_POST);
?>
$_GET
<?php
print_r($_GET);
?>
</PRE>
<?php
}

// Switch on search/add wizard step
switch( $_GET['step']){
// #################
// Search/Add form
// #################
case "1":
     $type = explode(":",$_POST['type']);
     if ($_POST['Submit']=="Add"){
         require($_POST['Submit'].$type[0].'.php');
     } else {
         if ( $_POST['type'] == "Movie:Movie" &&
             $_POST['MovieType'] == ""){
            header("Location:form4.php");
         }
?>
<h1>Search Results</h1>
<p>You are looking for a "<?php echo $type[1]?>" named "<?php echo $_POST['Name']?>"</p>
<?php
     }
     if ($_POST['Debug'] == "on"){
         debugDisplay();
     }
     break;
// #################
// Add Summary
// #################
case "2":
     $type = explode(":",$_POST['type']);
?>
<h1>New <?php echo $type[1]?> : <?php echo $_POST['Name']?></h1>
<?php
     switch( $type[0] ){
         case "Movie":
?>
<p>Released in <?php echo $_POST['MovieYear']?></p>
<p><?php echo nl2br(stripslashes($_POST['Desc']))?></p>
<?php
            break;
         default:
?>
<h2>Quick Bio</h2>
<p><?php echo nl2br(stripslashes($_POST['Bio']))?></p>
<?php
            break;
     }
     break;
// ###############
// Starting form
// ###############
default:
     require('startform.php');
     break;
}
?>


Addmovie.php:

<?php
if ( $_POST['type'] == "Movie:Movie" &&
        $_POST['MovieType'] == ""){
     header("Location:form4.php");
}
$title = $_POST['Submit']." ".$_POST['type']." : ".$_POST['Name'];
$name = $_POST['Name'];
$name[0] = strtoupper( $name[0]);
?>
<html>
<head>
<TITLE><?php echo $title?></TITLE>
</head>
<body>
<FORM action="form4.php?step=2" method="post">
<input type="hidden" name="type" value="<?php echo $type[1]?>">
<input type="hidden" name="action" value="<?php echo $_POST['Submit']?>">
<table border=0 width="750" cellspacing=1 cellpadding=3 bgcolor="#353535" align="center">
     <tr>
         <td bgcolor="#ffffff" width="30%">
            Movie Name
         </td>
         <td bgcolor="#ffffff" width="70%">
            <?php echo $name?>
            <input type="hidden" name="Name" value="<?php echo $name?>">
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff">
            Movie Type
         </td>
         <td bgcolor="#ffffff">
            <?php echo $_POST['MovieType']?><br />
            <input type="hidden" name="type" value="Movie: <?php echo $_POST['MovieType']?>">
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff">
            Movie Year
         </td>
         <td bgcolor="#ffffff">
            <SELECT name="MovieYear">
             <option value="" SELECTED>Select a year...</option>
<?php
for ($year=date("Y"); $year >= 1970 ;$year--){
?>
             <option value="<?php echo $year?>"><?php echo $year?></option>
<?php
}
?>
            </SELECT>
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff">
            Movie Description
         </td>
         <td bgcolor="#ffffff">
            <textarea name="Desc" rows="5" cols="60"></textarea>
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff" colspan=2 align="center">
            <INPUT type="SUBMIT" name="SUBMIT" value="Add">
         </td>
     </tr>
</table>
</FORM>
</body>
</html>

Addperson.php:

<?php
$title = $_POST['Submit']." ".$_POST['type']." : ".$_POST['Name'];
$name = $_POST['Name'];
$name[0] = strtoupper( $name[0]);
?>
<html>
<head>
<TITLE><?php echo $title?></TITLE>
</head>
<body>
<FORM action="form4.php?step=2" method="post">
<input type="hidden" name="type" value="Person: <?php echo $type[1]?>">
<input type="hidden" name="action" value="<?php echo $_POST['Submit']?>">
<table border=0 width="750" cellspacing=1 cellpadding=3 bgcolor="#353535" align="center">
     <tr>
         <td bgcolor="#ffffff" width="30%">
            <?php echo $type[1]?> Name
         </td>
         <td bgcolor="#ffffff" width="70%">
            <?php echo $name?>
            <input type="hidden" name="Name" value="<?php echo $name?>">
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff">
            Quick Bio
         </td>
         <td bgcolor="#ffffff">
            <textarea name="Bio" rows="5" cols="60"></textarea>
         </td>
     </tr>
     <tr>
         <td bgcolor="#ffffff" colspan=2 align="center">
            <INPUT type="SUBMIT" name="SUBMIT" value="Add">
         </td>
     </tr>
</table>
</FORM>
</body>
</html>

If it is missing something to understand it, tell me and I will post as reply.
Thank you very much!
 
Old September 3rd, 2006, 02:09 PM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

jotag,

I had no problem running your code 'as-is'. Perhaps I don't understand the complaint. Let's see what it does:

No matter whether you click "Search" or "Add", the line,
'<FORM action="form4.php?step=1" method="post">' forces you to form4.php where, under case=1, you query for 'Search' or 'Add'.
If you clicked 'Search', it displays what you're searching for. If you clicked 'Add', you should be getting another page (addmovie.php) where you have an opportunity to add more information.

Then, when you click 'Add' again, the line
'<FORM action="form4.php?step=2" method="post">'
sends you back to form4.php where you, now, execute the code in the second case.

In any case, when you fail to fill in some information, the default case in form4.php is executed. The line,
"require('startform.php');"
causes the code in "startform.php" to be displayed as though it were part of form4.php. That's why, in the default case, the address bar shows "form4.php" but the "startform.php" page is displayed.

Unless your browser is interpreting the code differently than mine, everything looks OK to me.

TG^2








Similar Threads
Thread Thread Starter Forum Replies Last Post
table2.php in chapter 4 - blank page ?? redarrow BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 April 13th, 2009 07:27 PM
PHP 5, Wrox, CH 7 navigator.php Jon_ BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 August 24th, 2008 01:13 PM
Beg. PHP 5 > Ch. 11 - fetch_field.php crater BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 January 2nd, 2007 12:20 PM
Ch5 : Form4.php pg 156-8 ... Not stepping iamdaniel BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 January 27th, 2006 12:58 PM
Ch. 1: PHP Installation Troubles: php3 vs php manjito BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 June 12th, 2003 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.