Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 2nd, 2012, 08:06 PM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch. 6 commit.php

Ok so this is the code from the book on Ch. 6 for the first commit.php,

Quote:
<?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;
}

if (isset($query)) {
$result = mysql_query($query, $db) or die(mysql_error($db));
}
?>
<p>Done!</p>
</body>
</html>
I've been getting an error and I think there's something wrong with the VALUES part of the query, can somebody tell me whether there is something wrong with this code and how to correct it?
Reply With Quote
  #2 (permalink)  
Old January 15th, 2012, 02:35 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can anybody help? Let me add some more details about what my question is and be more specific.
Code:
VALUES
("' . $_POST['movie_name'] . '",
' . $_POST['movie_year'] . ',
' . $_POST['movie_type'] . ',
' . $_POST['movie_leadactor'] . ',
' . $_POST['movie_director'] . ')';
I suspect that there's something wrong with the particular code above. My question is why is the first $_POST value encapsulated with both double-quotes and single quotes but the rest aren't? Also why does each $_POST have a period before and after it, isn't that used to concatenate something in PHP?
Reply With Quote
  #3 (permalink)  
Old January 15th, 2012, 10:00 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

Try the following, I've altered it slightly so that the query is wrapped in " and any text value being stored in the db is wrapped in ' I am unable to test it as I haven't got the db setup etc and the book is at work.

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

if (isset(
$query))
{
    
$result mysql_query($query$db) or die(mysql_error($db));
}
?>
<p>Done!</p>
</body>
</html>
And yes the period . is used to add some text to the $query string thus once complete you should get something like the following in $query;
Code:
INSERT INTO movie (movie_name, movie_year, movie_type, movie_leadactor, movie_director)
VALUES ('Dreamscape', '1988', 'Horror', 'Dennis Quaid', 'Joseph Ruben')

Last edited by UseLess; January 15th, 2012 at 10:11 AM..
Reply With Quote
  #4 (permalink)  
Old January 15th, 2012, 04:48 PM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by UseLess View Post
Greetings,

Try the following, I've altered it slightly so that the query is wrapped in " and any text value being stored in the db is wrapped in ' I am unable to test it as I haven't got the db setup etc and the book is at work.

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

if (isset(
$query))
{
    
$result mysql_query($query$db) or die(mysql_error($db));
}
?>
<p>Done!</p>
</body>
</html>
And yes the period . is used to add some text to the $query string thus once complete you should get something like the following in $query;
Code:
INSERT INTO movie (movie_name, movie_year, movie_type, movie_leadactor, movie_director)
VALUES ('Dreamscape', '1988', 'Horror', 'Dennis Quaid', 'Joseph Ruben')
Thanks, it worked!
Reply With Quote
  #5 (permalink)  
Old February 5th, 2012, 04:06 PM
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello all,

I have a problem also in ch 6 but in movie.php. I'm on page 157 i writed the code but i get each record of the Movie type,Year,Lead Actor,Director
two times.For example if a record for movie type is Action i get in list Action Action. Why ? Here is the code:

Code:
<?php
$db = mysql_connect('localhost','','') or 
	die('Unable to connect.Check your connection parameters');
	mysql_select_db('moviesite' ,$db) or die(mysql_error($db));
	
?>
<html>
<head>
<title>Add movie</title>
</head>
<body>
<form method="post" action="commit.php?action=add&type=movie">
  <table width="408" height="142" border="1">
    <tr>
      <td width="147">Movie Name</td>
      <td width="182">
      <input type="text" name="textfield" id="moviename"></td>
    </tr>
    <tr>
      <td>Movie Type</td>
      <td>
        <select name="movie_type">
	  <?php
	  $query = 'select movietype_id, movietype_label 
	  from movietype
	  ORDER BY 
	  movietype_label';
	  $result=mysql_query($query, $db) or die(mysql_error($db));

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
		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
		$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));
		  while($row = mysql_fetch_assoc($result)) {
			  foreach ($row as $value){
				  echo '<option value="' . $row['people_id'] . '">';
				  echo $row['people_fullname'] . '</option>';
			  }
		  }
		  ?>
      </select></td>
    </tr>
    <tr>
      <td>Director</td>
      <td>
        <select name="movie_director" >
        <?php
		$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));

// populate the select options with the results
while ($row = mysql_fetch_assoc($result)) {
    foreach ($row as $value) {
    	  echo '<option value="' . $row['people_id'] . '">';
	  	  echo $row['people_fullname'] . '</option>';
	}
}
    ?>
	  </select></td>
	 
    </tr>
	
  </table> <input type="submit" name="submit" value="Add"/>
</form>
</body>
</html>

Last edited by Stamatis; February 5th, 2012 at 04:11 PM..
Reply With Quote
  #6 (permalink)  
Old February 5th, 2012, 04:54 PM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

That's because you have a foreach inside the while loop, and you're not even using the foreach so remove it so it's like this:
Code:
while ($row = mysql_fetch_assoc($result))
{ 
	echo '<option value="' . $row['movietype_id'] . '">' . $row['movietype_label'] . '</option>';
}
Reply With Quote
  #7 (permalink)  
Old February 5th, 2012, 04:57 PM
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

its ok now.
perhaps it was a wrong of the book while the code was the same of the book

thank you
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 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



All times are GMT -4. The time now is 06:16 AM.


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