I wasn't getting any responses regarding my php/mysql database problem help. Here is the post.
Hi I need help regarding basic MySQL
I am doing this all by reading a programming book and following the directions but I think the book has some error and I can't figure it out, can someone help me.
So basically, when I open the file
table1.php this is what I get as the output.
Unknown column 'movietype' in 'field list'
I'm still a beginner so if someone could help me figure this out It'd be appreciated.
This is my code for the
table1.php:
Code:
<?php
//connect to MySQL
$db = mysql_connect('localhost', 'root', '') or
die('Unable to connect. Check your connection parameters.');
// make sure you're using the right database
mysql_select_db('moviesite', $db) or die(mysql_error($db));
// retrieve information
$query = 'SELECT
movie_name, movie_year, movie_director, movie_leadactor, movietype
FROM
movie
ORDER BY
movie_name ASC,
movie_year DESC';
$result = mysql_query($query, $db) or die(mysql_error($db));
// determine number of rows in returned result
$num_movies = mysql_num_rows($result);
?>
<div style="text-align: center;">
<h2>Movie Review Database</h2>
<table border="1" cellpadding="2" cellspacing="2"
style="width: 70%; margin-left: auto; margin-right: auto;">
<tr>
<th>Movie Title</th>
<th>Year of Release</th>
<th>Movie Director</th>
<th>Movie Lead Actor</th>
<th>Movie Type</th>
</tr>
<?php
// loop through the results
while ($row = mysql_fetch_assoc($result)) {
extract($row);
echo '<tr>';
echo '<td>' . $movie_name . '</td>';
echo '<td>' . $movie_year . '</td>';
echo '<td>' . $movie_director . '</td>';
echo '<td>' . $movie_leadactor . '</td>';
echo '<td>' . $movie_type . '</td>';
echo '</tr>';
}
?>
</table>
<p><?php echo $num_movies; ?> Movies</p>
</div>
This is my code for the Database
db_ch03-1.php
Code:
<?php
//connect to MySQL
$db = mysql_connect('localhost', 'root', '') or
die ('Unable to connect. Check your connection parameters.');
//create the main database if it doesn't already exist
$query = 'CREATE DATABASE IF NOT EXISTS moviesite';
mysql_query($query, $db) or die(mysql_error($db));
//make sure our recently created database is the active one
mysql_select_db('moviesite', $db) or die(mysql_error($db));
//create the movie table
$query = 'CREATE TABLE movie (
movie_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
movie_name VARCHAR(255) NOT NULL,
movie_type TINYINT NOT NULL DEFAULT 0,
movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0,
movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0,
movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (movie_id),
KEY movie_type (movie_type, movie_year)
)
ENGINE=MyISAM';
mysql_query($query, $db) or die (mysql_error($db));
//create the movietype table
$query = 'CREATE TABLE movietype (
movietype_id TINYINT NOT NULL AUTO_INCREMENT,
movietype_label VARCHAR(100) NOT NULL,
PRIMARY KEY (movietype_id)
)
ENGINE=MyISAM';
mysql_query($query, $db) or die(mysql_error($db));
//create the people table
$query = 'CREATE TABLE people (
people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
people_fullname VARCHAR(255) NOT NULL,
people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (people_id)
)
ENGINE=MyISAM';
mysql_query($query, $db) or die(mysql_error($db));
echo 'Movie database successfully created!';
?>