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 January 12th, 2010, 09:21 AM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Unhappy Chapter 4-Error message

Hello, i have some problem with file db_ch04-1.php on chapter 4 of book "Beginning PHP 6, Apache, Mysql 6 Web Development"
When browser run this file (db_ch04-1.php), there is an error message:
"Unknown column 'movie_running_time' in 'field list' " and I gave all privileges in mysql to user named 'bp6am'...
Thank you all in advance for each Help!
 
Old January 12th, 2010, 08:59 PM
Authorized User
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi rickymartini76,

I recall running into that problem as well... I believe it was because the user bp6am did not have the proper access (the ability to ALTER a table) in MySQL... However, you mention that you gave all privileges to bp6am.

If you are running MySQL on the same host as PHP/Apache, please run the following from the MySQL command line:

Code:
SHOW GRANTS FOR bp6am@localhost;
If you are running MySQL on a different host, please run the following commands:

Code:
SELECT user, host FROM mysql.user;
SHOW GRANTS FOR bp6am@###.###.###;   (###.###.###.### = associated IP address that is listed next to bp6am in the results for the SELECT command)
If you could post the results from the SHOW GRANTS and the contents of your db_ch04-1.php file.

Thanks!

Last edited by s.c.; January 12th, 2010 at 09:13 PM..
 
Old January 13th, 2010, 03:45 PM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Default Thank You

Thank you for your attention, but repeat that i gave all privileges to bp6am, en fact when i run your code ( SHOW GRANTS FOR bp6am@localhost;) i have this result:
Grants for bp6am@localhost

GRANT ALL PRIVILEGES ON *.* TO 'bp6am'@'localhost' IDENTIFIED BY PASSWORD '*36FC004FCCEF1BCFCE9233CF0633206BCD946F50'

while the contents of my db_ch04-1.php is the next:
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));

// modifica la tabella movie aggiungendo i campi per durata, incassi e costi
$query = 'ALTER TABLE movie ADD COLUMN (
       movie_running_time TINYINT UNSIGNED NULL,
       movie_cost         DECIMAL(4,1)     NULL,
       movie_takings      DECIMAL(4,1)     NULL)';
mysql_query($query, $db) or die (mysql_error($db));

// inserisce i nuovi dati nella tabella movie
$query = 'UPDATE movie SET
        movie_runnig_time = 101,
        movie_cost = 81,
        movie_takings = 242.6
    WHERE
        movie_id = 1';
mysql_query($query, $db) or die(mysql_error($db));

$query = 'UPDATE movie SET
        movie_running_time = 89,
        movie_cost = 10,
        movie_takings = 10.8
    WHERE
        movie_id = 2';
mysql_query($query, $db) or die(mysql_error($db));

$query = 'UPDATE movie SET
        movie_running_time = 134,
        movie_cost = NULL,
        movie_takings = 33.2
    WHERE
        movie_id = 3';
mysql_query($query, $db) or die(mysql_error($db));

echo 'Movie database successfully updated!';
?>
Thanks for your helps in advance.. ;-)
 
Old January 13th, 2010, 04:19 PM
Authorized User
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi Rickymartini,

Sorry, needed a starting point for the troubleshooting process...

You do have a typo in your code though.

Quote:
// inserisce i nuovi dati nella tabella movie
$query = 'UPDATE movie SET
movie_runnig_time = 101,
This line should be changed:

From:
movie_runnig_time = 101,
To:
movie_running_time=101,


FYI.
I found from experience that when you make a mistake on the db_ch#.php scripts that you may encounter additional errors after you make the corrections and re-run the script. This is because certain steps have already completed and updated the MySQL database.

You may or may not get error messages stating that column movie_running_time, movie_cost and movie_takings already exist and cannot add the column to the movie table.

If you do receive error messages similar to what I stated above, comment out the following lines:

Code:
// modifica la tabella movie aggiungendo i campi per durata, incassi e costi
$query = 'ALTER TABLE movie ADD COLUMN (
       movie_running_time TINYINT UNSIGNED NULL,
       movie_cost         DECIMAL(4,1)     NULL,
       movie_takings      DECIMAL(4,1)     NULL)';
mysql_query($query, $db) or die (mysql_error($db));
Hopefully it will work out, if not then the columns that were added to the database will have to be removed before you can get this script to work.
 
Old January 13th, 2010, 05:37 PM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Unhappy

Thanks, but it change nothing... I do this correction, but the result (error) is the same...
Before run code i deleted all moviesite database and i created it from begin..
Now the code is the next:
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));

// modifica la tabella movie aggiungendo i campi per durata, incassi e costi
$query = 'ALTER TABLE movie ADD COLUMN (
       movie_running_time TINYINT UNSIGNED NULL,
       movie_cost         DECIMAL(4,1)     NULL,
       movie_takings      DECIMAL(4,1)     NULL)';
mysql_query($query, $db) or die (mysql_error($db));

// inserisce i nuovi dati nella tabella movie
$query = 'UPDATE movie SET
        movie_runnig_time=101,
        movie_cost=81,
        movie_takings=242.6
    WHERE
        movie_id=1';
mysql_query($query, $db) or die(mysql_error($db));

$query = 'UPDATE movie SET
        movie_running_time=89,
        movie_cost=10,
        movie_takings=10.8
    WHERE
        movie_id=2';
mysql_query($query, $db) or die(mysql_error($db));

$query = 'UPDATE movie SET
        movie_running_time=134,
        movie_cost=NULL,
        movie_takings=33.2
    WHERE
        movie_id=3';
mysql_query($query, $db) or die(mysql_error($db));

echo 'Movie database successfully updated!';
?>
I don't know what to do...
Thanks
 
Old January 13th, 2010, 06:18 PM
Authorized User
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 4 Times in 4 Posts
Default Typo still exists...

you still have the same typo in the new code you just posted...
Quote:
movie_runnig_time=101,
In addition, this statement worries me:

Quote:
Before run code i deleted all moviesite database and i created it from begin..
From the MySQL command prompt, enter the following commands:

Code:
\u moviesite
SELECT * FROM movie;
Please list the results so we can see if your database table is indeed been recreated. Based on these results we can continue to troubleshoot the problem.

Any errors in the log files or on screen will be helpful as well.

Last edited by s.c.; January 13th, 2010 at 06:20 PM..
 
Old January 13th, 2010, 06:31 PM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by s.c. View Post
you still have the same typo in the new code you just posted...


In addition, this statement worries me:



From the MySQL command prompt, enter the following commands:

Code:
\u moviesite
SELECT * FROM movie;
Please list the results so we can see if your database table is indeed been recreated. Based on these results we can continue to troubleshoot the problem.

Any errors in the log files or on screen will be helpful as well.
After this command line this is the result on screen:
"Database changed"

Ok?
Thank you
 
Old January 13th, 2010, 08:06 PM
Authorized User
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Quote:
"Database changed"
This is the result of the "\u" moviesite command. "\u" = use this database "moviesite" = database name

You still need to issue the "SELECT" statement so we can see which columns are in the table "movie".

The "SELECT" statement has the output I would like to see.

Thanks

Example:

Quote:
mysql> \u moviesite
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SELECT * FROM movie;
+----------+----------------+------------+------------+-----------------+----------------+--------------------+------------+---------------+
| movie_id | movie_name | movie_type | movie_year | movie_leadactor | movie_director | movie_running_time | movie_cost | movie_takings |
+----------+----------------+------------+------------+-----------------+----------------+--------------------+------------+---------------+
| 1 | Bruce Almighty | 5 | 2003 | 1 | 2 | 101 | 81.0 | 242.6 |
| 2 | Office Space | 5 | 1999 | 5 | 6 | 89 | 10.0 | 10.8 |
| 3 | Grand Canyon | 2 | 1991 | 4 | 3 | 134 | NULL | 33.2 |
+----------+----------------+------------+------------+-----------------+----------------+--------------------+------------+---------------+
3 rows in set (0.00 sec)

mysql>

Last edited by s.c.; January 13th, 2010 at 08:11 PM..
 
Old January 14th, 2010, 03:41 PM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Question

Thanks, but after the command line the result is null :

mysql> SELECT * FROM movie;
+----------+----------------+------------+------------+-----------------+----------------+--------------------+------------+---------------+
| movie_id | movie_name | movie_type | movie_year | movie_leadactor | movie_director | movie_running_time | movie_cost | movie_takings |
+----------+----------------+------------+------------+-----------------+----------------+--------------------+------------+---------------+
| 1 | Bruce Almighty | 5 | 2003 | 1 | 2 | NULL | NULL | NULL |
| 2 | Office Space | 5 | 1999 | 5 | 6 | NULL | NULL | NULL |
| 3 | Grand Canyon | 2 | 1991 | 4 | 3 | NULL | NULL | NULL |
+----------+----------------+------------+------------+-----------------+----------------+--------------------+------------+---------------+
3 rows in set (0.00 sec)

And now What It means? Where is my mistake?
Thanks
 
Old January 14th, 2010, 05:07 PM
Authorized User
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Ok, the SELECT * FROM movie; = List everything (Columns and Rows) from the movie table

The fact that your table headers:

| movie_id | movie_name | movie_type | movie_year | movie_leadactor | movie_director | movie_running_time | movie_cost | movie_takings |

match mine, this means that in your code,
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));

// modifica la tabella movie aggiungendo i campi per durata, incassi e costi
$query = 'ALTER TABLE movie ADD COLUMN (
       movie_running_time TINYINT UNSIGNED NULL,
       movie_cost         DECIMAL(4,1)     NULL,
       movie_takings      DECIMAL(4,1)     NULL)';
mysql_query($query, $db) or die (mysql_error($db));
has successfully completed.

This next section failed because of a typo and the php script broke out with an error.

Because the php script broke out of its execution, your table was not updated. Thus causing NULL to remain in all of the row fields for the movie_running_time, movie_cost, and movie_takings columns.

Code:
// inserisce i nuovi dati nella tabella movie
$query = 'UPDATE movie SET
        movie_runnig_time=101,
        movie_cost=81,
        movie_takings=242.6
    WHERE
        movie_id=1';

The next step(s) to take are the following:


FIRST:

Comment out the following lines, because they are not needed anymore:

FROM:
Code:
// modifica la tabella movie aggiungendo i campi per durata, incassi e costi
$query = 'ALTER TABLE movie ADD COLUMN (
       movie_running_time TINYINT UNSIGNED NULL,
       movie_cost         DECIMAL(4,1)     NULL,
       movie_takings      DECIMAL(4,1)     NULL)';
mysql_query($query, $db) or die (mysql_error($db));
TO:
Code:
// modifica la tabella movie aggiungendo i campi per durata, incassi e costi
//$query = 'ALTER TABLE movie ADD COLUMN (
//       movie_running_time TINYINT UNSIGNED NULL,
//       movie_cost         DECIMAL(4,1)     NULL,
//       movie_takings      DECIMAL(4,1)     NULL)';
//mysql_query($query, $db) or die (mysql_error($db));

SECOND:

Fix the typo in this line (Line 15):

movie_runnig_time=101,



Once those changes are made, try running the php script again.

The following should occur:

1. PHP will connect to MySQL
2. The script will bypass the ALTER command.
3. The script will update the movie table for Bruce Almighty
4. The script will update the movie table for Office Space
5. The script will update the movie table for Grand Canyon.


THIRD:

Log into the MySQL command line.

Issue the \u moviesite and SELECT * FROM movie; commands and compare the output. They should match what I posted above.


Good Luck!

Last edited by s.c.; January 14th, 2010 at 05:17 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 : Message Contract Program Example thsun BOOK: Professional WCF Programming: .NET Dev with Windows Communication Found ISBN: 9780470089842 16 January 11th, 2008 12:34 PM
Chapter 7 Error message carlfoster BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 January 31st, 2007 02:07 PM





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