Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Hi I need some help regarding Basic MySQL/PHP
Old 07-28-2009, 09:32 PM Hi I need some help regarding Basic MySQL/PHP
Experienced Talker

Posts: 41
Name: Crystal
Location: Beverly Hills
Trades: 0
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!';
?>
__________________
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

majormusic is offline
Reply With Quote
View Public Profile Visit majormusic's homepage!
 
 
Register now for full access!
Old 07-29-2009, 01:08 AM Re: Hi I need some help regarding Basic MySQL/PHP
GeekSpecialties's Avatar
Super Talker

Posts: 132
Name: Leonard
Location: Minnesota, USA
Trades: 0
I'm certainly no expert, but did you try changing movietype to movie_type in this line?
Code:
movie_name, movie_year, movie_director, movie_leadactor, movietype
To match this
Code:
movie_type      TINYINT           NOT NULL DEFAULT 0,
GeekSpecialties is offline
Reply With Quote
View Public Profile Visit GeekSpecialties's homepage!
 
Old 07-29-2009, 03:23 PM Re: Hi I need some help regarding Basic MySQL/PHP
Experienced Talker

Posts: 41
Name: Crystal
Location: Beverly Hills
Trades: 0
Wow it worked, thank you very much.
__________________
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

majormusic is offline
Reply With Quote
View Public Profile Visit majormusic's homepage!
 
Old 07-29-2009, 04:30 PM Re: Hi I need some help regarding Basic MySQL/PHP
Experienced Talker

Posts: 41
Name: Crystal
Location: Beverly Hills
Trades: 0
Hi Geek I ran into another stump, can you help me out again. I can't figure this one out tried to do it for hours.

This is my table2.php code

Code:
<?php

//take in the id of a director and return his/her full name
function get_director($director_id) {
	
	global $db;
	
	$query = 'SELECT
			people_fullname
		FROM
			people
		WHERE
			people_id = ' . $director_id;
	$result = mysql_query($query, $db) or die(mysql_error($db));
	
	$row = mysql_fetch_assoc($result);
	extract($row);
	
	return $people_fullname;
}

//take in the id of a lead actor and return his/her full name
function get_leadactor($leadactor_id) {
	
	global $db;
	$query = 'SELECT
			people_fullname
		FROM
			people
		WHERE
			people_id = ' . $leadactor_id;
			
		$result = mysql_query($query, $db) or die(mysql_error($db));
		
		$row = mysql_fetch_assoc($result);
		extract($row);
		
		return $people_fullname;
}

//take in the id of a movie type and return the meaningful textual
//description

function get_movietype($type_id) {
	
	global $db;
	
	$query = 'SELECT
			movietype_label
		FROM
			movietype
		WHERE
			movietype_id ' . $type_id;
	$result = mysql_query($query, $db) or die(mysql_error($db));
	
	$row = mysql_fetch_assoc($result);
	extract($row);
	
	return $movietype_label;
}

//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, movie_type
	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);

$table = <<<ENDHTML
<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>
ENDHTML;

//loop through the results
while ($row = mysql_fetch_assoc($result)) {
	extract($row);
	$director = get_director($movie_director);
	$leadactor = get_leadactor($movie_leadactor);
	$movietype = get_movietype($movie_type);
	
	$table .= <<<ENDHTML
<tr>
	<td>$movie_name</td>
	<td>$movie_year</td>
	<td>$director</td>
	<td>$leadactor</td>
	<td>$movietype</td>
</tr>
ENDHTML;
}

$table .= <<<ENDHTML
</table>
<p>$num_movies Movies</p>
</div>
ENDHTML;

echo $table;
?>


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!';
?>
__________________
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

majormusic is offline
Reply With Quote
View Public Profile Visit majormusic's homepage!
 
Old 07-29-2009, 05:00 PM Re: Hi I need some help regarding Basic MySQL/PHP
Experienced Talker

Posts: 41
Name: Crystal
Location: Beverly Hills
Trades: 0
Oh I forgot to tell you what error I get. The error I get is:

Table 'moviesite.people' doesn't exist
__________________
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

majormusic is offline
Reply With Quote
View Public Profile Visit majormusic's homepage!
 
Old 08-06-2009, 08:12 PM Re: Hi I need some help regarding Basic MySQL/PHP
Experienced Talker

Posts: 41
Name: Crystal
Location: Beverly Hills
Trades: 0
Can anyone still help me. It's been a couple days and I still cannot figure this out.
__________________
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

majormusic is offline
Reply With Quote
View Public Profile Visit majormusic's homepage!
 
Old 08-07-2009, 07:08 AM Re: Hi I need some help regarding Basic MySQL/PHP
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
It seems the people table doesn't exist. Are you sure it has been successfully created?
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-10-2009, 08:13 PM Re: Hi I need some help regarding Basic MySQL/PHP
Experienced Talker

Posts: 41
Name: Crystal
Location: Beverly Hills
Trades: 0
Yes it has been created. But how can I double check?
__________________
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

majormusic is offline
Reply With Quote
View Public Profile Visit majormusic's homepage!
 
Old 08-11-2009, 06:40 AM Re: Hi I need some help regarding Basic MySQL/PHP
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Please show a bit of code or the query being run when the error occurs.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-30-2009, 12:07 PM Re: Hi I need some help regarding Basic MySQL/PHP
Experienced Talker

Posts: 41
Name: Crystal
Location: Beverly Hills
Trades: 0
Table 'moviesite.people' doesn't exist

This is the error I get when I try to open it.

Thank you
__________________
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

majormusic is offline
Reply With Quote
View Public Profile Visit majormusic's homepage!
 
Old 08-30-2009, 06:32 PM Re: Hi I need some help regarding Basic MySQL/PHP
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I'm sorry but I can't see what's wrong. Since MySQL is saying the table doesn't exist, it probably doesn't. Either it isn't created at all, or you've made some spelling mistake or similar (check for big and small letters) so that MySQL is looking for the wrong table.

I did find another error though, but it will not fix this problem. In the function get_movietype() the line
Code:
movietype_id ' . $type_id;
should be

Code:
movietype_id = ' . $type_id;
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Hi I need some help regarding Basic MySQL/PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34905 seconds with 12 queries