Wrox Programmer Forums
|
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
 
Old February 2nd, 2009, 02:57 PM
Registered User
 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Setting up createmovie.php, moviedata.php

I finally got my MySQL to work with PHP, but anyway, I'm on the third chapter, setting up the movie database.

When I run createmovie.php I have success. However, when I go to moviedata.php, I get the error: Duplicate entry '1' for key 'PRIMARY'

Any clue what is causing this? The code looks like:
HTML Code:
<?php

$link = mysql_connect('localhost', 'root');
if (!$link) {
    die('Not connected : ' . mysql_error());
}
//select database
mysql_select_db("wiley");

//insert data into "movie" 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 Carrey', 1, 0),
  (2, 'Tom Shadyac', 0, 1),
  (3, 'Lawrence Kasdan', 0, 1),
  (4, 'Kevin Kline', 1, 0),
  (5, 'Ron Livington', 1, 0),
  (6, 'Mike Judge', 0, 1)";
$results=mysql_query($people)
    or die(mysql_error());
    
echo "Data inserted successfully!";
?>
 
Old November 23rd, 2009, 03:11 PM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default THe Same thing

i have the same Problem did u figer out what was the problem
finally got my MySQL to work with PHP, but anyway, I'm on the third chapter, setting up the movie database.

When I run createmovie.php I have success. However, when I go to moviedata.php, I get the error: Duplicate entry '1' for key 'PRIMARY'

Any clue what is causing this? The code looks like:
HTML Code:
<?php

$link = mysql_connect('localhost', 'root');
if (!$link) {
die('Not connected : ' . mysql_error());
}
//select database
mysql_select_db("wiley");

//insert data into "movie" 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
 
Old December 28th, 2009, 01:24 PM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Experienced Errors

ephemera-

at the top of your code where it reads:

Code:
$link = mysql_connect('localhost', 'root');
change it to this:
Code:
$link = mysql_connect('localhost', 'root', "");
when attempting to connect to a MySQL database you need to provide
3 things: [server][user][password] ( "" indicates no password)

goodboy-

when you get errors like " Duplicate entry '1' for key 'PRIMARY'"
that indicates that some of the code ran but with errors. You need to clear the tables that were created by delving into MySQL via the DOS prompt.
I used the xampp download from apachefriends so the following gets me to MySQL on my computer:

CHDIR C:\xampp
c:xampp>mysql\bin\mysql -h localhost -u root

This gets you to the mysql> prompt, once there enter the following:
SHOW DATABASES; (to see what's there)
USE moviesite; (the database for the first project in this book)
SHOW TABLES; (show all the tables made)
DROP TABLE movie;
DROP TABLE movietype;
DROP TABLE people; (drop these tables to clear them)

then run createmovie.php and moviedata.php again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
potential createmovie.php error ElizabethN BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 8 August 25th, 2004 09:46 AM
Setting up mySQL with PHP SuperDude PHP How-To 1 July 30th, 2004 06:47 AM
createmovie.php logon trouble JohnAlden BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 May 25th, 2004 01:11 PM
Error troubleshooting - createmovie.php samgman BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 May 13th, 2004 01:24 AM
createmovie.php joebloggs BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 11 April 26th, 2004 06:37 PM





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