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

February 20th, 2012, 04:56 PM
|
Registered User
|
|
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Undefined index: type
Hello can anyone help I ve been getting the following error message and I don't know how to fix it. I don't have no parse errors or mistakes.
the error is for delete.php in chapter 6 page 164. Whenever, I try to delete a record in admin.php I get the message below.
Notice: Undefined index: type in /Applications/MAMP/htdocs/php_6/chap6/delete.php on line 6
also the echo strings for "Are you sure you want to delete this movie?" does show up and the strings for "your movie has been deleted. Return to Index" doesn't show up as well. Thanks
here is the code for delete.php
Code:
<?php
$db = mysql_connect('localhost', 'xmx', 'xcv') or die('Unable to connect. Check your parameters.');
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 delete.<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 delete.<a href="movie_index.php">Return to Index</a></p>
<?php
break;
}
}
?>
|

February 20th, 2012, 05:23 PM
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
|
|
Greetings,
When the script is called it expects parameters so using this:
delete.php
will result in errors as the script expects to be called like this:
delete.php?type=movie&id=2
Upon first calling the script the parameter 'do' is not set so you get asked the question, based on the supplied 'type', are you sure you want to delete the record. At which point 'do' is added to the URL, with the following line:
Code:
echo '<a href="' . $_SERVER['REQUEST_URI'] . '&do=1">yes</a>';
and set to 1 therefore when 'Yes' is clicked the appropriate record is then deleted as the code in the 'else' is ran as 'do' isset and it is set to 1 so the 'if', this bit:
Code:
if (! isset($_GET['do']) || $_GET['do'] != 1)
does not equate to true so the code in the 'else' section is ran.
So you'll need to check the file that links to the delete.php file and make sure the links have the parameters applied correctly.
|

February 20th, 2012, 06:09 PM
|
Registered User
|
|
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the help I solved the problem!
Hello, I'd like to thank you very much base on your explanations I figured out what the problem was.
The mistake was in admin.php I had
Code:
<a href="delete.php?action =movie&id=' .
instead of
Code:
<a href="delete.php?type=movie&id='
.
Thanks again
|

September 22nd, 2014, 04:55 PM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi guys,
I have a problem with delete.php file: I can't delete the item choosen (Test movie). In fact, when I click DELETE in the admin.php file, nothing happens to the item.
The code of delete.php is the following:
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));
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 movie has been deleted. <a href="movie_index.php">Return do Index</a></p>
<?php
break;
}
}
?>
and the code of admin.php is
Code:
<?php
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or
die ('Unable to connect. Check your database parameters');
mysql_select_db('moviesite', $db) or die (mysql_error($db));
?>
<html>
<head>
<title>Movie database</title>
<style type="text/css">
th { background: #999; }
.odd_row { background: #eee; }
.even_row { background: #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>
Any solution?
Thanks in advance ;-)
|

September 23rd, 2014, 05:44 AM
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
|
|
Greetings,
In 'delete.php' you DO NOT have any code to handle the delete request. And the code to remove a person has the output line from the movie delete... your switch statement should be like this;
Code:
switch ($_GET['type'])
{
case 'people':
// code in here to remove people
break;
case 'movie':
// code in here to remove movies
break;
}
what you have is this;
Code:
switch ($_GET['type'])
{
case 'people':
// code in here to remove people
break;
}
|

September 23rd, 2014, 06:37 AM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks a lot, UseLess.
The code in the book does not run, as you know.
Thanks to your tip, I added the following code and it runs:
Code:
<?php
// Break of the 'people' case
break;
// Start the 'movie' case
case 'movie':
$query = 'UPDATE movie SET
movie_id = 0
WHERE
movie_name =' . $_GET['id'];
$result = mysql_query($query, $db) or die (mysql_error($db));
$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 do Index</a></p>
<?php
break;
}
}
?>
Maybe useful for those who met the same problem ;-)
|
|
 |