Problem Accessing MySql Database
Posted: Sun Jun 04, 2006 8:19 am
I am very new to MySql and tried to create a MySql database on a Windows local server (Apche server), with the script below. I granted the user privilledges to SELECT, INSERT & UPDATE, When I attampted to run the script on my browser, It returned with this error message; "Access denied for user 'bp5am'@'localhost' to database 'moviesite' " but when I checked with phpMyAdmin I had the user in my list and also the database moviesite. I will also be happy if my script can be checked for future errors.
Below is the script I am having problem with;
When I also try to run the script that populates the database moviesite, this is the error message i receive "Table 'moviesite.movietype' doesn't exist"
below is the script that populates the database;
Below is the script I am having problem with;
Code: Select all
<?php
$host = "localhost";
$user = "bp5am";
$pass = "bp5ampass";
//connect to MySQL
$connect = mysql_connect($host, $user, $pass);
// die ("Hey loser, check your server connection.");
//creater the main database if it does not exist
$create = mysql_query("CREATE DATABASE IF NOT EXISTS moviesite")
or die(mysql_error());
//make sure our recently created database is the active one
mysql_select_db("moviesite");
//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)
)";
$results = mysql_query($movie)
or die (mysql_error());
//create "moviesite" table
$movietype = "CREATE TABLE movietype (
movie_id int(11) NOT MULL auto_increment,
movietype_label varchar(100) NOT NULL,
PRIMARY KEY (movietype_id)
)";
$results = mysql_query($movietype)
or die(mysql_error());
//create "people" table
$people = "CREATE TABLE people (
people-id int(11) NOT NULL auto_increment,
people_fulname varchar(255) NOT NULL,
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!";
?>When I also try to run the script that populates the database moviesite, this is the error message i receive "Table 'moviesite.movietype' doesn't exist"
below is the script that populates the database;
Code: Select all
<?
//connect to MySQL
$host = "localhost";
$user = "bp5am";
$pass = "bp5ampass";
//connect to MySQL
$connect = mysql_connect($host, $user, $pass);
or die ("Hey losser, check your server connection.");
//make sure we're using the right database
mysql_select_db("moviesite");
//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 "moviesite" table
$type = "INSERT INTO movietype (movietype_id, movietype_label1) " .
"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, 'Kelvin Kline', 1, 0),".
"(5, 'Ron Livingstone', 1, 0),".
"(6, 'Mike Judge', 0, 1)";
$results = mysql_query($people)
or die(mysql_error());
echo "Data inserted successfully!";
?>