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

October 12th, 2004, 02:48 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
}
?>
|
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 |
|
 |