p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 (http://p2p.wrox.com/forumdisplay.php?f=123)
-   -   Error: movie.php & commit.php on p182-186, ch6 (http://p2p.wrox.com/showthread.php?t=19749)

willburke October 12th, 2004 02:48 PM

Error: movie.php & commit.php on p182-186, ch6
 
I enter the following code, but it don't update the database, any help would be really great! I can't find the code reference in the download code on the site also.

This is movie.php
<?php
    //Connect to the database *************************
    $link = mysql_connect("localhost","root","xxxxxxxx") or die("Could not connect: " . mysql_error());

    //Use the correct database **************************
    mysql_select_db('chapter6', $link) or die(mysql_error());

    //Get information to populate the form to add a new movie *******************
    $peoplesql = "SELECT *
                  FROM people";
    $results = mysql_query($peoplesql) or die("Invalid query: " .mysql_error());
    while( $row = mysql_fetch_array( $results , MYSQL_ASSOC))
    {
        $people[$row['people_id']] = $row['people_fullname'];
    }

    switch( $_GET['action'] )
    {
        case "edit":
            $moviesql = "SELECT *
                         FROM
                            movie
                         WHERE
                            movie.movie_id = '".$_GET['id']."'
                        ";
            $result = mysql_query($moviesql) or die("Invalid query 2: " . mysql_error());
            $row = mysql_fetch_array( $result , MYSQL_ASSOC );
            $movie_name = $row[ 'movie_name' ];
            $movie_type = $row[ 'movie_type' ];
            $movie_year = $row[ 'movie_year' ];
            $movie_leadactor = $row[ 'movie_leadactor' ];
            $movie_director = $row[ 'movie_director' ];
            break;
        default:
            $movie_name = "";
            $movie_type = "";
            $movie_year = "";
            $movie_leadactor = "";
            $movie_director = "";
            break;
    }
?>
<html>
<head>
    <TITLE><?php echo $_GET['action']?> movie</TITLE>
</head>
<body>
<FORM action="commit.php?action=<?php echo $_GET['action']?>&type=movie&id=<?php echo $_GET['id']?>" method="post">
    <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">
                <input type="text" name="movie_name" value="<?php echo $movie_name?>">
            </td>
        </tr>
        <tr>
            <td bgcolor="#ffffff">
                Movie Type
            </td>
            <td bgcolor="#ffffff">
                <SELECT id="game" name="movie_type" style="width:150px">
    <?php
                $sql = "SELECT
                            movietype_id, movietype_label
                        FROM
                            movietype
                        ORDER BY
                            movietype_label
                        ";
                $result = mysql_query($sql) or die("Query Error". mysql_error());
                while($row = mysql_fetch_array($result))
                {
                    if ($row['movietype_id'] == $movie_type)
                    {
                        $selected = " SELECTED";
                    }
                    else
                    {
                        $selected = "";
                    }
                        echo'<OPTION value="'.$row['movietype_id'].'"'.$selected.'>'.$row['movietype_label'].'</OPTION>'."\r\n";
                }
        ?>
                </SELECT>
                </td>
            </tr>
            <tr>
                <td bgcolor="#ffffff">
                    Movie Year
                </td>
                <td bgcolor="#ffffff">
                    <SELECT name="movie_year">
                        <option value="" SELECTED>Select a year...</option>
        <?php
        for ($year=date("Y"); $year >= 1970 ;$year--)
        {
            if ( $year == $movie_year)
            {
                $selected = " SELECTED";
            }
            else
            {
                $selected = "";
            }
        ?>
                        <option value="<?php echo $year?>"<?php echo $selected?>><?php echo $year?></option>
        <?php
        }
        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td bgcolor="#ffffff">
                    Lead Actor
                </td>
                <td bgcolor="#ffffff">
                    <SELECT name="movie_leadactor">
                        <option value="" SELECTED>Select an actor...</option>
    <?php
    foreach($people as $people_id => $people_fullname)
    {
        if ( $people_id == $movie_leadactor)
        {
            $selected = " SELECTED";
        }
        else
        {
            $selected = "";
        }
    ?>
                        <option value="<?php echo $people_id?>"<?php echo $selected?>><?php echo $people_fullname?></option>
    <?php
    }
    ?>
                    </SELECT>
                </td>
            </tr>
            <tr>
                <td bgcolor="#ffffff">
                    Director
                </td>
                <td bgcolor="#ffffff">
                    <SELECT name="movie_director">
                        <option value="" SELECTED>Select a director...</option>
    <?php
    foreach( $people as $people_id => $people_fullname )
    {
        if ( $people_id == $movie_director)
        {
            $selected = " SELECTED";
        }
        else
        {
            $selected = "";
        }
    ?>
                        <option value="<?php echo $people_id?>"<?php echo $selected?>><?php echo $people_fullname?></option>
    <?php
    }
    ?>
                    </SELECT>
                </td>
            </tr>
            <tr>
                <td bgcolor="#ffffff" colspan=2 align="center">
                    <INPUT type="SUBMIT" name="SUBMIT" value="<?php echo $_GET['action']?>">
                </td>
            </tr>
        </table>
    </FORM>
</body>
</html>

This is commit.php
<?php
    //COMMIT ADD AND EDITS
    //Connect to the mysql server
    $link = mysql_connect("localhost","root","xxxxxxxx") or die("Could not connect: " . mysql_error());

    //Use the correct database
    mysql_select_db('chapter6',$link) or die(mysql_error());

    //Code Commit Action
    switch($_GET['action'])
    {
        case "edit":
            switch( $_GET['type'] )
            {
                case "movie":
                    $sql = "UPDATE
                                movie
                            SET
                                movie_name = '".$_POST['movie_name']."',
                                movie_year = '".$_POST['movie_year']."',
                                movie_type = '".$_POST['movie_type']."',
                                movie_leadactor = '".$_POST['movie_leadactor']."',
                                movie_director = '".$_POST['movie_director']."'
                            WHERE
                                movie_id = '".$GET['id']."'
                           ";
                    break;
            }
            break;
        case "add":
            switch($_GET['type'])
            {
                case "movie":
                    $sql = "INSERT INTO
                                movie
                                (movie_name,movie_year,movie_type,movie_leadactor, movie_director)
                            VALUES
                                ('".$_POST['movie_name']."',
                                '".$_POST['movie_year']."',
                                '".$_POST['movie_type']."',
                                '".$_POST['movie_leadactor']."',
                                '".$_POST['movie_director']."')
                            ";
                break;
            }
        break;
    }
    if (isset($sql) && !empty($sql))
    {
        echo "";
        $result = mysql_query($sql) or die("Invalid query: " . mysql_error());
?>
        <p align="center" style="color:#ff0000">
            Done. <a href="index.php">Index</a>
        </p>
<?php
    }
?>


All times are GMT -4. The time now is 04:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.