Need help creating a table in MySQL
Posted: Sat Nov 02, 2002 6:53 am
i have been using the tutorials on http://www.phpcomplete.com and they help me understand mysql and php alot. but i as i was following a tutorial, it said to create a table and it showed the code for it.
So with that i asume it works.. but when i go to retrieve that information it says that table friends does not exisit. My code for my retrieve page is:
please help me figure out why it is not creating the table.. thanks
Code: Select all
<html>
<title>Test Project</title>
<?php
$dbconn = mysql_connect("localhost", "deado", "password");
$result = mysql_select_db("deadzone", $dbconn);
if ( $result == false )
{
echo mysql_error();
} else {
echo "Yay! We connected successfully!";
}
?>
<?php
CREATE TABLE friends
(
fid TINYINT not null AUTO_INCREMENT,
fname VARCHAR (20) not null ,
lname VARCHAR (20) not null ,
birthday DATE not null ,
address VARCHAR (100) not null ,
city VARCHAR (20) not null ,
state VARCHAR (2) not null ,
zip VARCHAR (7) not null ,
country VARCHAR (20) not null ,
email VARCHAR (60) not null ,
phone VARCHAR (14) not null ,
notes MEDIUMTEXT not null ,
PRIMARY KEY (fid)
)
?>
<?php
INSERT INTO `friends`
(
`fid`,
`fname`,
`lname`,
`birthday`,
`address`,
`city`,
`state`,
`zip`,
`country`,
`email`,
`phone`,
`notes`
)
VALUES
(
'',
'Jason',
'Lotito',
'1980-01-19',
'Somewhere',
'Montreal',
'CN',
'12345',
'Canada',
'jason@lehighweb.com',
'1234567890',
'These are notes and are whatever I want them to be. =))'
)
?>
</html>Code: Select all
<html>
<title>Retrieve</title>
<?php
$dbconn = mysql_connect("localhost", "deado", "password");
$result = mysql_select_db("deadzone", $dbconn);
if ( $result == false )
{
echo mysql_error();
} else {
$sql = "SELECT fname, lname, email FROM friends WHERE fid=1";
$result = mysql_query( $sql );
if ( $result != false )
{
echo "Query was successful";
} else {
echo mysql_error();
}
}
?>
</html>