Wrox Programmer Forums
|
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 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 January 24th, 2010, 05:22 AM
Registered User
 
Join Date: Jan 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem. Chapter 6 Page 158(157,158,159,160)

I have a problem for some reason the drop down boxes in movie.php are doubling up the actor and director options? Does anyone know what is wrong?

Here is the code for the three pages used...but only the first two are relevent...

Click on ADD next to movies on the first page and then you see in the drop down boxes they are doubling up.

for admin.php
PHP Code:
<?PHP 

$db 
mysql_connect('localhost''bp6am''bp6ampass') or 
    die(
'Unable to Connect. Please check connection settings.');

mysql_select_db('moviesite'$db) or die(mysql_error($db));

?>

<html>
<head>
<title>Movie Database</title>

<style type="text/css">

th {background-color:#999;}
.odd_row {background-color:#EEE;}
.even_row {background-color:#FFF;}

</style>
</head>
<body>
<table style="width:100%;">
<tr>
    <th colspan="2">Movies <a href="movie.php?action=add">[ADD]</a></th>
</tr>
<?php
$query 
'SELECT * FROM movie';
$result mysql_query($query$db) or die(mysql_error($db));

$odd true;
while (
$row mysql_fetch_assoc($result)){
    echo (
$odd == true) ? '<tr class="odd_row">' '<tr class="even_row">';
    
$odd = !$odd;
    echo 
'<td style="width:75%";>';
    echo 
$row['movie_name'];
    echo 
'</td><td>';
    echo 
'<a href="movie.php?action=edit&id='.$row['movie_id'].'">[EDIT]</a>';
    echo 
'<a href="delete.php?type=movie&id='.$row['movie_id'].'">[DELETE]</a>';
    echo 
'</td></tr>';
}
?>
<tr>
    <th colspan="2">People <a href="people.php?action=add">[ADD]</a></th>
</tr>

<?php 
$query 
'SELECT * FROM people';
$result mysql_query($query$db) or die(mysql_error($db));
$odd true;
while (
$row mysql_fetch_assoc($result)){
    echo (
$odd == true) ? '<tr class="odd_row">' '<tr class="even_row">';
    
$odd = !$odd;
    echo 
'<td style="width:25%";>';
    echo 
$row['people_fullname'];
    echo 
'</td><td>';
    echo 
'<a href="people.php?action=edit&id='.$row['people_id'].'">[EDIT]</a>';
    echo 
'<a href="delete.php?type=people&id='.$row['people_id'].'">[DELETE]</a>';
    echo 
'</td></tr>';
}
?>
</table>
</body>
</html>
for movie.php
PHP Code:
<?php
$db 
mysql_connect('localhost''bp6am','bp6ampass') or 
    die(
'Unable to Connect. Plerase Check your conneciton parameters.');

mysql_select_db('moviesite'$db) or die(mysql_error($db));
?>
<html>
<head>
<title>Add Movie</title>
</head>
<body>
<form action="commit.php?action=add&type=movie" method="post">
<table>
<tr>
    <td>Movie Name</td>
    <td><input type="text" name="movie_name"/></td>
</tr>
<tr>
    <td>Movie Type</td>
    <td>
        <select name="movie_type">
<?php
//select the movie type 
$query 'SELECT 
            movietype_id, movietype_label
        FROM
            movietype
        ORDER BY
            movietype_label'
;

$result mysql_query($query$db) or die(mysql_error($db));

//populate the select options with the results
while ($row mysql_fetch_assoc($result)){
    foreach (
$row as $value){
        echo 
'<option value="'.$row['movietype_id'].'">';
        echo 
$row['movietype_label'].'</option>';
    }
}
?>
        </select>
    </td>
</tr>
<tr>
    <td>Movie Year</td>
    <td>
        <select name="movie_year">
        <?php
        
//populate the select options with years
        
for ($yr date("Y"); $yr >=1970$yr--){
            echo 
'<option value"'.$yr.'">'.$yr.'</option>';
        }
        
?>
        </select>
    </td>
</tr>
<tr>
    <td>Lead Actor</td>
    <td><select name="movie_leadactor">
    <?php
    
//select actor records
    
$query'SELECT
                people_id, people_fullname
            FROM
                people
            WHERE
                people_isactor=1
            ORDER BY
                people_fullname'
;
    
$result mysql_query($query$db) or die(mysql_error($db));
     
    
//populate the select options with the results
    
while($row mysql_fetch_assoc($result)){
        foreach(
$row as $value){
            echo 
'<option value="'.$row['people_id'].'">'.$row['people_fullname'].'</option>';
        }
    }
    
?>
    </select>
    </td>
</tr>
<tr>
    <td>Director</td>
    <td>
    <select name="movie_director">
    <?php
    
//select director records
    
$query ='SELECT 
                people_id, people_fullname
            FROM
                people
            WHERE
                people_isdirector = 1
            ORDER BY 
                people_fullname'
;

    
$result mysql_query($query$db) or die(mysql_error($db));
    
    while (
$row mysql_fetch_assoc($result)){
        foreach (
$row as $value){
            echo 
'<option value="'.$row['people_id'].'">'.$row['people_fullname'].'</option>'
        }
    }
    
?>
    </select>
    </td>
</tr>
<tr>
    <td colspan="2" style="text-align:center;">
        <input type="submit" name="submit" value="Add"/>
    </td>
</tr>
</table>
</table>
</form>
</body>
</html>
for commit.php
PHP Code:
<?php
$db 
mysql_connect('localhost''bp6am','bp6ampass') or
die (
'Unable to connect. Please check connection parameters');

mysql_select_db('moviesite',$db) or die(mysql_error($db));
?>

<html>
<head>
<title>Commit</title>
</head>
<body>
<?php
switch ($_GET['action']){
    case 
'add':
        switch(
$_GET['type']){
            case
'movie':
                
$query '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(
$query)){
    
$result mysql_query($query$db) or die(mysql_error($db));
}
                
?>
<p>Done!</p>
</body>
</html>
 
Old January 24th, 2010, 05:27 AM
Registered User
 
Join Date: Jan 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default The code from WROX site is doing this as WELL. ERROR!

I downloaded the does from the wrox site and its doing the same thing?

Whats wrong with the code?

oh and movie type is doing it aswell!

Thanks.

Truth
 
Old January 24th, 2010, 05:42 AM
Registered User
 
Join Date: Jan 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Solved!

Ok if you take out the foreach statements then it works!

while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $value) {
echo '<option value"' . $row['movietype_id'] . '">';
echo $row['movietype_label'] . '</option>';
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Begin.Php5,,Chap04, page no.158,,ex. dynamic.php sandeepgreaternoida BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 1 November 5th, 2013 12:13 PM
Errata: Ch. 6, Page 157 drupalmeister BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 6 September 27th, 2010 05:33 PM
Errata: Ch. 6, Page 157 drupalmeister BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 June 3rd, 2009 08:28 PM
Chapter 5 | Pg.158 - Step 2 jwriddle BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 30th, 2009 02:03 AM
Page 160 garak0410 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 January 16th, 2006 11:24 AM





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