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

January 30th, 2010, 08:28 PM
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
|
|
Chap. 6 - delete.php - page 164
Two questions:
The code in the example handles the Cascade Delete if you delete the lead actor, but seems to omit the case of deleting a director? Don't we need to do the same thing if the user tries to delete a director?
Secondly, when we update the movie_leadactor field to '0', is that going to cause problems, since there is no one in the people table with an id of 0?
TIA,
Boz
|

February 19th, 2010, 10:43 AM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chap. 6 - delete.php
Hi all, guys.
I have a problem with the page delete.php: when I try to delete the movie "Test", I see this error:
Quote:
Notice: Undefined index: do in C:\Programmi\EasyPHP5.3.0\www\film\delete.php on line 5
Are you sure you want to delete this movie?
yesor no
|
This is the delete.php code:
PHP Code:
<?php
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or die ('Unable to connect');
mysql_select_db('moviesite', $db) or die (mysql_error($db));
if(isset($_GET['do']) || $_GET['do'] != 1) {
switch ($_GET['type']) {
case 'movie':
echo 'Are you sure you want to delete this movie?<br />';
break;
case 'people':
echo 'Are you sure you want to delete this person?<br />';
break;
}
echo '<a href="' . $_SERVER['REQUEST_URI'] . '&do=1">yes</a>';
echo 'or <a href="admin.php">no</a>';
}
else
{
switch ($_GET['type']) {
case 'people':
$query = 'UPDATE movie SET
movie_leadactor = 0
WHERE
movie_leadactor = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
$query = 'DELETE FROM people
WHERE
people_id = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
?>
<p style="text-align: center;">Your person has been deleted. <a href="movie_index.php">Return to Index</a></p>
<?php
break;
case 'movie':
$query = 'DELETE FROM movie
WHERE
movie_id = ' . $_GET['id'];
$result = mysql_query($query, $db) or die(mysql_error($db));
?>
<p style="text-align: center;">Your movie has been deleted. <a href="movie_index.php">Return to index</a>
<?php
break;
}
}
?>
It seems that 'do' is not defined. How can I solve this?
Thanks
|

February 19th, 2010, 03:51 PM
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
|
|
Solution
You're right. the first time through 'do' is not defined and shouldn't be.
You have a mistake in the code on line 5. You need to add an "!" before the isset function, thus:
Code:
if(!isset($_GET['do']) || $_GET['do'] != 1) {
What's happens with an "OR" condition is that the first expression gets evaluated, if it's true, the "OR" is satisfied and it doesn't even look at the second condition. If it's false, it looks at the second one to see if IT is true. That's what is happening here. It's looking at $_GET['do'] != 1 and causing the error.
Your code is asking first if the 'do' is set. Since it isn't, it evaluates to false and looks at the second condition which is where your error occurs.
What needs to happen is the first condition needs to ask if the 'do' is NOT set. Since it isn't, this evaluates to TRUE, the "OR" is satisfied and it never bothers to look at the $_GET['do'] != 1 part, so no errors.
In short, just add that ! to "NOT OUT" the isset, and you should be fine.
Regards, and welcome to the forum!
Boz
|

February 22nd, 2010, 09:47 AM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks a lot, Boz!
I meet several errors in the scripts and I don't know why. For example:
Quote:
Notice: Undefined index: action in C:\Programmi\EasyPHP5.3.0\www\film\movie.php on line 5
Movie Name
Movie Type
Movie Year
Lead Actor
Director
Notice: Undefined index: action in C:\Programmi\EasyPHP5.3.0\www\film\movie.php on line 141
|
and this is the code of movie.php:
PHP Code:
<?php
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or die ('Unable to connect');
mysql_select_db('moviesite', $db) or die (mysql_error($db));
if ($_GET['action'] == 'edit') {
//recuperare le informazioni del record
$query = 'SELECT
movie_name, movie_type, movie_year, movie_leadactor, movie_director
FROM
movie
WHERE
movie_id = '. $_GET['id'];
$result = mysql_query($query, $db) or die (mysql_error($db));
extract(mysql_fetch_assoc($result));
} else {
//azzera i valori
$movie_name = '';
$movie_type = 0;
$movie_year = date('Y');
$movie_leadactor = 0;
$movie_director = 0;
}
?>
<html>
<head>
<title><?php echo ucfirst($_GET['action']); ?> Movie</title>
</head>
<body>
<form action="commit.php?action=<?php echo $_GET['action']; ?>&type=movie" method="post">
<table>
<tr>
<td>Movie Name</td>
<td><input type="text" name="movie_name" value="<?php echo $movie_name; ?>" /></td>
</tr>
<tr>
<td>Movie Type</td>
<td>
<select name="movie_type">
<?php
//seleziona il tipo di film
$query = 'SELECT
movietype_id, movietype_label
FROM
movietype
ORDER BY
movietype_label';
$result = mysql_query($query, $db) or die (mysql_error($db));
//popola le opzioni della select con i risultati
while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $value) {
if ($row['$movietype_id'] == $movie_type) {
echo '<option value="' . $row['$movietype_id'] . '" selected="selected">';
} else {
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
//popola le opzioni della select con gli anni
for ($yr = date("Y"); $yr >= 1970 and $yr <= 2020; $yr++) {
echo '<option value="' . $yr . '">' . $yr . '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td>Lead Actor</td>
<td><select name="movie_leadactor">
<?php
//seleziona i record degli attori
$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));
//popola le opzioni della select con i risultati
while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $value) {
if ($row['$people_id'] == $movie_leadactor) {
echo '<option value="' . $row['$people_id'] . '" selected="selected">';
} else {
echo '<option value="' . $row['people_id'] . '">';
}
echo $row['people_fullname'] . '</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<td>Director</td>
<td>
<select name="movie_director">
<?php
//seleziona i record dei registi
$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));
//popola le opzioni della select con i risultati
while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $value) {
if ($row['$people_id'] == $movie_director) {
echo '<option value="' . $row['$people_id'] . '" selected="selected">';
} else {
echo '<option value="' . $row['people_id'] . '">';
}
echo $row['people_fullname'] . '</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<?php
if ($_GET['action'] == 'edit') {
echo '<input type="hidden" value="' . $_GET['id'] . '" name="movie_id" />';
}
?>
<input type="submit" name="submit" value="<?php echo ucfirst ($_GET['action']); ?>" />
</td>
</tr>
</table>
</form>
</body>
</html>
|

February 22nd, 2010, 01:13 PM
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
|
|
possible solution
I don't see a problem in your script. I think it's probably in your admin.php file. movie.php is expecting to be called like this:
movie.php?action=edit&type=movie
This call puts information in the $_GET array. You can see it when you hover your mouse over the link.
Look for the lines in admin.php that contain:
href="movie.php?action=
My guess is that one of them has action spelled incorrectly. If not, just post the code for admin.php and I'll have a look.
Also check out the post I started with "Tip: echo vs print". I posted some code and at the bottom there are some lines you can put at the end of movie.php that display the contents of the $_GET and $_POST arrays. I use this to keep track of what my programs are passing back and forth to each other. Hope this helps.
Boz
|

September 27th, 2010, 04:38 PM
|
Authorized User
|
|
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Issue with code
Hi I'm having a similar error with this example. Everytime I run the script and click delete all I get is "yes or no" and nothing else. Please help. THanks.
PHP Code:
<?php if (!isset($_GET['do']) || $_GET['do'] !=1) { switch ($_GET['type']) { case 'movie': echo 'Are you sure you want to delete this movie?<br/>'; break; case 'people': echo 'Are you sure you want to delete this person?<br/>'; break; } echo '<a href="' . $_SERVER['REQUEST_URI'] . '&do=1">yes</a> '; echo 'or <a href="admin.php">no</a>'; } else { switch ($_GET['type']) { case 'people': $query = 'UPDATE movie SET movie_leadactor=0 WHERE movie_leadactor = ' . $_GET['id']; $results = mysql_query($query) or die(mysql_error());
$query = 'DELETE FROM people WHERE people_id= ' . $_GET['id']; $results = mysql_query($query) or die(mysql_error()); ?>
<p style="text-align:center;">Your person has been deleted. <a href="movie_index.php">Return to index</a></p>
<?php break; case 'movie': $query = 'DELETE FROM movie WHERE movie_id = ' . $GET['id']; $results = mysql_query($query) or die(mysql_error()); ?>
<p style="text-align: center;">Your movie has been deleted. <a href="movie_index.php">Return to index</a></p>
<?php break; } } ?>
Last edited by hozdaman; September 27th, 2010 at 05:02 PM..
Reason: fix code
|
Similar Threads
|
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
Chap 2, Some small errors in add_post.php and view.php |
kenj |
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 |
0 |
October 22nd, 2009 07:48 PM |
php/mysql delete button and delete query |
dungey |
PHP Databases |
17 |
April 11th, 2009 12:24 PM |
Page 164 - Where is "chapter6,mysql"? |
Kevin Tough |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 |
0 |
July 9th, 2007 03:37 PM |
Commit.PHP and Delete.PHP in WROX's book |
GiFos |
Beginning PHP |
0 |
January 30th, 2007 10:51 PM |
Chap 9 - Charedit.php |
IP076 |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 |
3 |
December 1st, 2004 08:17 PM |
|
 |