Beginner: Stuck and can't figure it out, please advise

Discussion in 'PHP' started by ph33rgear, Dec 16, 2006.

  1. #1
    Ok i'm trying to get this script to make a database but it keeps giving me an error, which i can't seem to figure out why. Maybe someone can look at it and let me know, i just can't see it right now.

    <?php
    //connect to MySQL; note we've user our own parameters - you should use
    //your own for hostname, user, password
    $connect=mysql_connect("localhost","account","password") or
    		die ("hey idiot, check your server connection.");
    		
    //create the main database
    mysql_create_db("database_name")
    		or die(mysql_error());
    
    // make sure our recently created database is an active one
    mysql_select_db("database_name");
    
    //create "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)
    ) TYPE=MyISAM auto_increment=4 ";
    
    $results=mysql_query($movie)
    	or die (mysql_error() );
    	
    //create "movietype" table
    $movietype="create table people (
    movietype_id int(11) not null auto_increment,
    movietype_label varchar(100) not null,
    primary key (movietype_id)
    ) type=MyISAM auto_increment=9";
    
    $results=mysql_query($movietype)
    	or die(mysql_error());
    	
    //create "people" table
    $people="create table people (
    people_id int(11) not null auto_increment,
    people_fullname varchar(255) not null,
    people_isactor tinyint(1) not null default 0,
    people_isdirector tinyint(1) not null default 0,
    primary key (people_id)
    ) type=MyISAM auto_increment=7";
    
    $results=mysql_query($people)
    	or die(mysql_error());
    	
    echo "Movie Database creation Successfull!";
    
    ?>
    PHP:
    and i get this error

    any ideas?

    THANKS!
     
    ph33rgear, Dec 16, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Your hosting has probably disabled the function mysql_create_db(). The number of databases databases might be limited in you hosting plan, and/or can only be created through the CP.
     
    nico_swd, Dec 16, 2006 IP
  3. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Typically you should create databases from scripts, most users do not have permission in production environments to create databases anyway, just delete the mysql_create_db command and do it in phpmyadmin, leave the select database func there
     
    krakjoe, Dec 16, 2006 IP
  4. ph33rgear

    ph33rgear Active Member

    Messages:
    211
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    it's my computer that is the server, so what can i switch on to make it work?
     
    ph33rgear, Dec 16, 2006 IP
  5. Austars

    Austars Active Member

    Messages:
    1,437
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    95
    #5
    Get phpmyadmin to do it. Its much more user friendly as well.
     
    Austars, Dec 16, 2006 IP
  6. ph33rgear

    ph33rgear Active Member

    Messages:
    211
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #6
    i have it already, just need to know what to do?

    Or you meant to add the db and tables etc..?

    cuz the point of making this is to learn, so that's why i'm doing it this way for now...
     
    ph33rgear, Dec 16, 2006 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Try

    
    mysql_query("CREATE DATABASE $dbname") or die("Couldn't Create Database: $dbname"); 
    
    PHP:
     
    nico_swd, Dec 16, 2006 IP
  8. hereyago

    hereyago Active Member

    Messages:
    389
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #8
    why not create db with your host?
     
    hereyago, Dec 16, 2006 IP
  9. Austars

    Austars Active Member

    Messages:
    1,437
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    95
    #9
    Please read the thread, he's hosting it on his own computer with wamp :rolleyes:
     
    Austars, Dec 16, 2006 IP
  10. ph33rgear

    ph33rgear Active Member

    Messages:
    211
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #10
    thanks, that did work, although it did say that one of the tables was created already, i check though and it was fine.

    now i have a different error lol, when i run the script to enter the data hehe i'm not having a good day for this, maybe i should pick up again tomorrow :)

    <?php 
    //connect to mysql
    $connect=mysql_connect("localhost", "account", "pass") or
    	die("hey shithead!, Check your server connection.");
    	
    //make sure we're using the right db
    mysql_select_db("db_name");
    
    //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',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 "movie_type" 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, 'Lawrence Kasdan', 0, 1),
    (3, 'Tom Shadyac', 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!";
    ?>
    
    PHP:

    Error:
    ahhh isn't learning so much fun, but i guess its better to run into mistakes and learn rather then have it all go smooth and not really learn that stuff. kinda helps you understand it all a bit more.

    Thanks for the help so far it is appreciated!:)
     
    ph33rgear, Dec 16, 2006 IP
  11. ph33rgear

    ph33rgear Active Member

    Messages:
    211
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #11
    well i'm trying to learn how to create files that will make the database and then input the information from a script.... so then in the future I can make an auto install script for anything that i learn to write...

    long ways from that but it's fun so far :D
     
    ph33rgear, Dec 16, 2006 IP
  12. Austars

    Austars Active Member

    Messages:
    1,437
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    95
    #12
    Where are you learning PHP/MySQL from?
     
    Austars, Dec 16, 2006 IP
  13. ph33rgear

    ph33rgear Active Member

    Messages:
    211
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #13
    Beginning PHP, Apache, MySQL Web Development

    from www.Wrox.com
     
    ph33rgear, Dec 16, 2006 IP
  14. Austars

    Austars Active Member

    Messages:
    1,437
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    95
    #14
    Well I was about to create databases and tables and stuff fine from the tutorial at www.w3schools.com , perhaps you should check those out.
     
    Austars, Dec 16, 2006 IP
  15. ph33rgear

    ph33rgear Active Member

    Messages:
    211
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #15
    I like to read it from a book kinda, dunno just do. Also I paid 60$ for this book from chapters so you can bet i'm gonna read it all ;)

    I will also look at those too though, :D
     
    ph33rgear, Dec 16, 2006 IP