Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 12th, 2004, 02:48 PM
Registered User
 
Join Date: Oct 2004
Location: , , Canada.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to willburke
Default 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
    }
?>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Commit.PHP and Delete.PHP in WROX's book GiFos Beginning PHP 0 January 30th, 2007 10:51 PM
chapter 7 commit.php ratxamala BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 November 2nd, 2005 09:24 AM
ch 6 commit.php problem updating movie table statusquo BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 May 2nd, 2005 10:02 PM
Chapter 6 commit.php czambran BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 October 3rd, 2004 10:20 PM
ch 7 page 208 commit.php pipdickenz BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 September 8th, 2004 12:08 PM



All times are GMT -4. The time now is 01:55 AM.


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