Subject: Ch5 : Form4.php pg 156-8 ... Not stepping
Posted By: iamdaniel Post Date: 1/11/2006 4:02:17 AM
They seem to skip a step between 7 and 8 on page 157. They say to load form4.php and enter a movie name. The next step they say to add the film's year (but that's not even an option on this form.

When I hit "Add" or "Search" at the bottom of my form, it brings me to the same page with the Debug Dump, but not the AddMovie.php or AddPerson.php.

My code is correct. There are no parse errors. Can someone please help?

CODE:
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['Sumbit']=="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 n12br(stripslashes($_POST['Desc']))?></p>
<?php
        break;
    default:
?>
<h2>Quick Bio</h2>
<p><?php echo n12br(stripslashes($_POST['Bio']))?></p>
<?php
        break;
    }
    break;
    //starting form
    default;
        require('startform.php');
        break;
}
?>

=============================

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=1 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>

==========================================

addmovie.php

<?php
    if ($_POST['type'] == "Movie:Movie" && $_POST['MovieType'] == ""){
        header("Location:form4.php");
    }
    $title = $_POST['Sumbit']." ".$_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="1" width="750" cellspacing=1 cellpadding=3 align="center">
        <tr>
            <td width="30%">
                Movie Name
            </td>
            <td width="70%">
                <?php echo $name?>
                <input type="hidden" name="name" value="<?php echo $name?>">
            </td>
        </tr>
        <tr>
            <td>
                Movie Type
            </td>
            <td>
                <?php echo $_POST['MovieType']?><br />
                <input type="hidden" name="type" value="Movie: <?php echo $_POST['MovieTy[e']?>">
            </td>
        </tr>
        <tr>
            <td>
                Movie Year
            </td>
            <td>
                <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>
                Movie Description
            </td>
            <td>
                <textarea name="Desc" rows="5" cols="60"></textarea>
            </td>
        </tr>
        <tr>
            <td 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=1 width=750 cellspacing=1 cellpadding=3 align="center">
        <tr>
            <td width="30%">
                <?php echo $type[1]?> Name
            </td>
            <td>
                <?php echo $name?>
                <input type="hidden" name="Name" value="<?php echo $name?>">
            </td>
        </tr>
        <tr>
            <td>
                Quick Bio
            </td>
            <td>
                <textarea name="Bio" rows="5" cols="60"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan=2 align="center">
                <input type="submit" name="submit" value="add">
            </td>
        </tr>
    </table>
</form>
</body>
</html>

========================
I'm assuming that in startform.php they have us send the form data to form4.php, which is why there is AddMovie or AddPerson in the sequence.

I'm constantly having to check the forums for solutions to every other problems.




Reply By: Pheeal Reply Date: 1/27/2006 11:53:51 AM
Ah iamdaniel, I think I spotted it!

In your code for Form4.php there is a ; where the should be a :

It's on the 3rd (well 5th) line up from the bottom
default;

    default;
        require('startform.php');
        break;
}
?>


I hope that's it as I didn't read the rest - jumping to conclusions

The thing is I'm stuck on the same chapter, and it looks like everyone's new year resolution is to learn PHP from THIS book, when every chapter you have to do a lot of googling - the main reason I registered here!

My form4.php wont display anythin just a blank page...
Reply By: Pheeal Reply Date: 1/27/2006 11:58:19 AM
Spotted another thing:

addmovie.php

<?php
    if ($_POST['type'] == "Movie:Movie" && $_POST['MovieType'] == ""){
        header("Location:form4.php");
    }
    $title = $_POST['Sumbit']." ".$_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="1" width="750" cellspacing=1 cellpadding=3 align="center">
        <tr>
            <td width="30%">
                Movie Name
            </td>
            <td width="70%">
                <?php echo $name?>
                <input type="hidden" name="name" value="<?php echo $name?>">
            </td>
        </tr>
        <tr>
            <td>
                Movie Type
            </td>
            <td>
                <?php echo $_POST['MovieType']?><br />
                <input type="hidden" name="type" value="Movie: <?php echo $_POST['MovieTy[e']?>">

this last line - you missed the p key and hit [ instead

Go to topic 39220

Return to index page 384
Return to index page 383
Return to index page 382
Return to index page 381
Return to index page 380
Return to index page 379
Return to index page 378
Return to index page 377
Return to index page 376
Return to index page 375