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 June 24th, 2010, 08:55 AM
Authorized User
 
Join Date: Jun 2010
Posts: 36
Thanks: 1
Thanked 1 Time in 1 Post
Question Chp 6: Optional exercise

Hi (sorry for my english but i'm Italian)

In the only one optional excercise of chp 6 ask me to make the people.php page for edit/delete the options of the actors and directors.
I start trying to build a part of script for only edit people. I want to change with radio button the choice for set the people as actor or director, but don't works

This is the people.php script (works well, make list of people in a select form, and check the radio button if are actors or directors, i know is useless make a optional list but i made it for make practice)
PHP Code:
<?php

$db 
mysql_connect('localhost''bp6am''bp6ampass') or
    die (
'Unable to connect. Check your connection parameters.');
mysql_select_db('moviesite'$db) or die (mysql_error($db));

?>
<html>
<head><title>People</title></head>
<body>
<form action=commit.php?action=<?php echo $_GET['action']; ?>&type=people" method="post">
Edit People:<br/>



<select name="movie_type">

<?php
//select the people name
$query 'SELECT
        people_id, people_fullname
    FROM
        people
    ORDER BY
        people_fullname'
;
$result mysql_query($query$db) or die(mysql_error($db));

//populate the select with names
while ($row mysql_fetch_assoc($result)) {
    foreach (
$row as $value) {
        if (
$row['people_id'] == $_GET['id']) {
            echo 
'<option value="' $row['people_id'] .
                
'" selected="selected">';
        } else {
            echo 
'<option value="' $row['people_id'] . '">';
        }
        echo 
$row['people_fullname'] . '</option>';
    }
}
?>
</select>
<?php
//check the radio if actor or director
$query 'SELECT
        people_id, people_isactor, people_isdirector
    FROM
        people
    WHERE
    people_id = ' 
$_GET['id'];
$result mysql_query($query$db) or die(mysql_error($db));

        
$row mysql_fetch_assoc($result);
             
        if (
$row['people_isactor'] == 1) {
        echo 
'Actor<input type="radio" value="' $row['people_isactor'] . '" name="selezione" checked="checked" />';
    }  else {
        echo 
'Actor<input type="radio" value="' $row['people_isactor'] . '" name="selezione" />';
        }
        
//secondo if per verificare regista
        
if ($row['people_isdirector'] == 1) {
        echo 
'Director<input type="radio" value="' $row['people_isdirector'] . '" name="selezione" checked="checked" />';
    }  else {
        echo 
'Director<input type="radio" value="' $row['people_isdirector'] . '" name="selezione" />';
        } 
echo 
'<br /><br />';
echo 
'<input type="submit" name="submit" value="' ucfirst($_GET['action']) . '" />'
echo 
'<br /><p style="color: red;">Debug:<br />';
echo 
print_r($row);    
echo 
'<br /></p>';
?>
    
</form>
</body>
</html>
and this is the commit.php , don't works..
PHP Code:
<?php
$db 
mysql_connect('localhost''bp6am''bp6ampass') or 
    die (
'Unable to connect. Check your 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;
case 
'edit':
    switch (
$_GET['type']) {
    case 
'movie':
        
$query '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 = ' 
$_POST['movie_id'];
        break;
    
    case 
'people':
      
$query 'UPDATE people SET
           people_isactor = ' 
$_POST['selezione'] . ',
           people_isdirector = ' 
$_POST['selezione'] . '
          WHERE
            people_isactor = ' 
.$_POST['people_id'].',
            people_isdirector = ' 
$_POST['people_id'];
      break;
   }
}

if (isset(
$query)) {
    
$result mysql_query($query$db) or die(mysql_error($db));
}
?>
  <p>Done!</p>
 </body>
</html>
Can you help me please? Thanks!
 
Old August 31st, 2012, 08:16 AM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb My work

Here is my optional code .. made by mysefl for people.php and commit.php
It is working fine i guess :))

That's people.php

PHP Code:
<?php
    $link 
mysql_connect("localhost","bp5am","bp5ampass") or die(mysql_error());
    
mysql_select_db("chapter6"$link) or die(mysql_error());
    
    switch (
$_GET['action'])
    {
        case 
"edit":
            
$peoplesql "SELECT * FROM people
                          WHERE people_id = '" 
$_GET['id'] . "'";
            
$result mysql_query($peoplesql) or die(mysql_error());
            
$row mysql_fetch_array($result);
            
$people_fullname $row['people_fullname'];
            
$people_isactor $row['people_isactor'];
            
$people_isdirector $row['people_isdirector'];
            break;
        default:
            
$people_fullname "";
            
$people_isactor "";
            
$people_isdirector "";
            break;
    }
?>

<html>
    <head>
        <title><?php echo ucfirst($_GET['action']); ?></title><style type="text/css">
        TD{color:#353535; font-family:verdana}
        TH{color:#FFFFFF; font-family:verdana; background-color:#336699}
        </style>
    </head>
    <body>
        <form action="commit.php?action=<?php
            
echo $_GET['action']; ?>&type=people&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="50%">Name of the person</td>
                <td bgcolor="#FFFFFF" width="50%">
                    <input type="text" name="people_fullname" value="<?php echo $people_fullname?>">
                </td>
            </tr>
            <tr>
                <td bgcolor="#FFFFFF" width="50%">The person is</td>
                <td bgcolor="#FFFFFF" width="50%">an actor
<?php
    
if ($people_isactor == 1)
    {
        
$checked " checked";
    }
    else
    {
        
$checked "";
    }
?>
                    <input type="radio" name="ppl" value="people_isactor"<?php echo $checked?>>
                </td>
            </tr>
            <tr>
                <td bgcolor="#FFFFFF" width="50%">
                </td>
                <td bgcolor="#FFFFFF" width="50%">a director
<?php
    
if ($people_isdirector == 1)
    {
        
$checked " checked";
    }
    else
    {
        
$checked "";
    }
?>
                    <input type="radio" name="ppl" value="people_isdirector"<?php echo $checked?>>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" name="SUBMIT" value="<?php echo ucfirst($_GET['action']); ?>">
                </td>
            </tr>
        </table>
        </form>
    </body>
</html>
and that's the commit.php code:

PHP Code:
<?php
    
//COMMIT ADD AND EDITS
    
$link mysql_connect("localhost","bp5am","bp5ampass") or die(mysql_error());
    
mysql_select_db("chapter6"$link) or die(mysql_error());
    
    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;
                case 
"people":
                    if (
$_POST['ppl'] == "people_isactor")
                    {
                        
$isactor 1;
                        
$isdirector 0;
                    }
                    else
                    {
                        
$isactor 0;
                        
$isdirector 1;
                    }
                    
$sql "UPDATE people SET
                                people_fullname = '" 
$_POST['people_fullname'] . "',
                                people_isactor = '
$isactor',
                                people_isdirector = '
$isdirector'
                            WHERE people_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;
                case 
"people":
                    if (
$_POST['ppl'] == "people_isactor")
                    {
                        
$isactor 1;
                        
$isdirector 0;
                    }
                    else
                    {
                        
$isactor 0;
                        
$isdirector 1;
                    }
                    
$sql "INSERT INTO people
                                (people_fullname,
                                 people_isactor,
                                 people_isdirector)
                            VALUES
                                ('" 
$_POST['people_fullname'] . "',
                                 '
$isactor',
                                 '
$isdirector')";
                    break;
            }
            break;
    }
    
    if (isset(
$sql) && !empty($sql))
    {
        echo 
"<!--" $sql "-->";
        
$result mysql_query($sql) or die(mysql_error());
?>

<p align="center" style="color:#FF0000">
    Done. <a href="index.php">Index</a>
</p>

<?php
    
}
?>
Thumbs up for me :)))





Similar Threads
Thread Thread Starter Forum Replies Last Post
Optional prameters and C#? NewTitle2007 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 2 August 5th, 2007 12:17 PM
Argument not Optional aziaraphale Excel VBA 5 August 1st, 2007 02:53 AM
Adding optional columns? shaileshmark SQL Server 2000 9 July 24th, 2004 03:57 PM
optional parameters in SP yuqlin BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 7 July 13th, 2004 03:28 PM
Optional WHERE clause in sproc KYC SQL Language 2 February 17th, 2004 03:40 PM





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