 |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0  | This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 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
|
|
|
|

March 27th, 2005, 01:34 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Help with code
There is either something wrong with the code on pg. 95-96, or I am doing something wrong:
<?php
//connect to mysql
$connect = mysql_connect("localhost", "root", "root")
or die ("Hey! Check your server connection");
//make sure checking right DB
mysql_select_db("moviesite");
//insert data into table
$insert = "INSERT INTO movie (movie_id, movie_name, movie_type, " .
"movie_year, movie_leadactor, movie_director) " .
"VALUES (1, 'Bruce Almighty', 5, 2003, 1, 2), " .
"(2, 'Office Space', 5, 1999, 5, 6), " .
"(3, 'Grand Canyon', 2, 1991, 4, 3), ";
$results = mysql_query($insert)
or die(mysql_error());
//insert data into "movietype" table
$type = "INSERT INTO movietype (movietype_id, movietype_label) " .
"VALUES (1, 'Sci Fi'), " .
"(2, 'Drama'), " .
"(3, 'Adventure'), " .
"(4, 'War'), " .
"(5, 'Comedy'), " .
"(6, 'Horror'), " .
"(7, 'Action'), " .
"(8, 'Kids'), " .
$results = mysql_query($type)
or die (mysql_error());
//insert data into "people" table
$people = "INSERT INTO people (people_id, people_fullname, " .
"people_isactor, people_isdirector) " .
"VALUES (1, 'Jim Carey', 1, 0), " .
"(2, 'Tom Shadyac', 0, 1), " .
"(3, 'Lawrence Kasdan', 0, 1), " .
"(4, 'Kevin Kline', 1, 0), " .
"(5, 'Ron Livingston', 1, 0), " .
"(6, 'Mike Judge', 0, 1)";
$results = mysql_query($people)
or die(mysql_error());
echo "Data inserted successfully!";
?>
Does anyone know what I am doing wrong?
Thanks for your help,
-andrea
|
|

April 9th, 2005, 12:09 PM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Andrea,
Does the following work:
<?php
//connect to mysql
$connect = mysql_connect("localhost", "root", "root")
or die ("Hey! Check your server connection");
//make sure checking right DB
mysql_select_db("moviesite");
//insert data into table
$insert = "INSERT INTO movie (movie_id, movie_name, movie_type, " .
"movie_year, movie_leadactor, movie_director), " .
"VALUES (1, 'Bruce Almighty', 5, 2003, 1, 2), " .
"(2, 'Office Space', 5, 1999, 5, 6), " .
"(3, 'Grand Canyon', 2, 1991, 4, 3), ";
$results = mysql_query($insert)
or die(mysql_error());
//insert data into "movietype" table
$type = "INSERT INTO movietype (movietype_id, movietype_label) " .
"VALUES (1, 'Sci Fi'), " .
"(2, 'Drama'), " .
"(3, 'Adventure'), " .
"(4, 'War'), " .
"(5, 'Comedy'), " .
"(6, 'Horror'), " .
"(7, 'Action'), " .
"(8, 'Kids'), " .
$results = mysql_query($type)
or die (mysql_error());
//insert data into "people" table
$people = "INSERT INTO people (people_id, people_fullname, " .
"people_isactor, people_isdirector) " .
"VALUES (1, 'Jim Carey', 1, 0), " .
"(2, 'Tom Shadyac', 0, 1), " .
"(3, 'Lawrence Kasdan', 0, 1), " .
"(4, 'Kevin Kline', 1, 0), " .
"(5, 'Ron Livingston', 1, 0), " .
"(6, 'Mike Judge', 0, 1)";
$results = mysql_query($people)
or die(mysql_error());
echo "Data inserted successfully!";
?>
I placed a comma after:
$insert = "INSERT INTO movie (movie_id, movie_name, movie_type, " .
"movie_year, movie_leadactor, movie_director),
Bye,
|
|

April 19th, 2005, 09:43 PM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The format for INSERT is:
INSERT INTO file (fieldlist) VALUES (valuelist),(valuelist),(etc)
There's not supposed to be a comma between the field list and the VALUES keyword. If you look at the $type and $people strings, they're done exactly the same way.
..KARL...
<SPAN ATTRIB="DORK">KarlGG</SPAN>
|
|
 |