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, 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 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 June 17th, 2005, 09:29 AM
Registered User
 
Join Date: May 2005
Location: , Oregon, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default needing help with mysql stuff in ch 3

here is the code :
saved as createmovie.php per pg 94-95

<?php
//connect to mysql
$connect=mysql_connect("localhost", "root", "*******") or
    die ("Hey man, check your server connection.");

//creating main database
$create=mysql_query("CREATE DATABASE IF NOT EXISTS moviesite")
    or die(mysql_error());

//making sure new database is the active one
mysql_select_db("moviesite");

//creating "movie" table
$movie="CREATE TABLE movie (
     movie_id int(11) NOT NULL auto_increment,
     movie_name varchar(255) NOT NULL,
     movie_type tinyint(2) NOT NULL default 0,
     movie_year int(4) NOT NULL default 0,
     movie_leadactor int(11) NOT NULL default 0,
     movie_director int(11) NOT NULL default 0,
     PRIMARY KEY (movie_id),
     KEY movie_type (movie_type,movie_year)
)";

$results=mysql_query($movie)
   or die(mysql_error());

//creating "movietype" table
$movietype="CREATE TABLE movietype (
   movietype_id int(11) NOT NULL auto_increment,
   movietype_label varchar(100) NOT NULL,
   PRIMARY KEY (movietype_id)
)";

$results=mysql_query($movietype)
   or die(mysql_error());

//creating "people" table
$people="CREATE TABLE people (
   people_id int(11) NOT NULL auto_increment,
   people_fullname varchar(255) NOT NULL default 0,
   people_isactor tinyint(1) NOT NULL default 0,
   people_isdirector tinyint(1) NOT NULL default 0,
   PRIMARY KEY (people_id)
)";

$results=mysql_query($people)
   or die(mysql_error());

echo "Movie Database successfully created!";
?>


and
moviedata.php per page 95-96:

<?php
//connect msql
$connect=mysql_connect("localhost", "root", "*****")
   or die ("Hey man, check your server connection.");

//choosing right db
mysql_select_db("moviesite");

//inserting 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 19
$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 32
$people="INSERT INTO people (people_id, people_fullname, " .
    "people_isactor, people_isdirector) " .
    "VAULES (1, 'Jim Carrey', 1, 0), " .
    "(2, 'Tom Shadyac', 0, 1), " .
    "(3, 'Lawrence Kasdan', 0, 1), " .
    "(4, 'Keven 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!";
?>



the issue is that when irun moviedata.php i get this error:
           Duplicate entry '1' for key 1


i was wondering if anyone knows what the problem could be.

thanks

Reply With Quote
  #2 (permalink)  
Old June 18th, 2005, 08:03 AM
Authorized User
 
Join Date: May 2005
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you run moviedata.php before? and if so, did you get an error?
If you had, the part of the data has already been added to the database hence why it's showing an error.

The way around this, is to remove the info that the script added to the database and then run the script again.

Reply With Quote
  #3 (permalink)  
Old June 27th, 2005, 01:39 AM
Registered User
 
Join Date: May 2005
Location: , Oregon, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, i did run it once and got an error...i thought it might be easier to get phpmyadmin installed and running, but after i got it installed and tried running http://localhost/phpmyadmin/index.php i get a 403 error saying that i dont have permission to access it on this server...any ideas on what the issue might be?

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
Newbie Needing Help reverett Classic ASP Basics 5 May 19th, 2005 06:14 PM
Needing help for chapter 1 fhzaki BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 October 25th, 2004 10:30 AM
needing help about date time picker anilkumarindiaa BOOK: Beginning Access VBA 2 January 11th, 2004 02:59 PM
needing help for formula editor in crystal report anilkumar Crystal Reports 1 January 7th, 2004 04:13 PM



All times are GMT -4. The time now is 01:30 PM.


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