PDA

View Full Version : Create Table Not Creating My Sql Table



Archbob
November 3rd, 2002, 22:09
<?php
$mysql_link = mysql_connect("localhost", "username", "password")
or die("Could not connect");
$SQL[]="CREATE TABLE guests (
guest_id int(4) unsigned zerofill DEFAULT '0000' NOT NULL auto_increment,
guest_name varchar(50),
guest_email varchar(50),
guest_time timestamp(14),
guest_message text,
PRIMARY KEY (guest_id)

);";


$SQL[]="INSERT INTO guests ( guest_id, guest_name, guest_email, guest_time, guest_message ) values( 0000,'Tony','tony@awtrey.com',NULL,'This is how it works!' )";

?>


Hey I ran this script and when I go to my phpadmin, I don't see a table guest. Of course username and password were mine and the database connected successfully.

Salam
November 4th, 2002, 15:58
You havent executed the queries :
After each $SQL[]=... ; add :
$result = mysql_query($SQL[]) ;

Archbob
November 4th, 2002, 23:12
Thanks. But I still a "no databas selected. Whats wrong? How should I change my code?

Salam
November 5th, 2002, 04:51
You can see your current databases by :
echo mysql_query("SHOW DATABASES;") ; // or mysql_list_dbs();
You can make a new database :
echo mysql_query("CREATE DATABASE my_db_name ;") ; // or mysql_create_db("my_db_name")) ;
Then you can select one of your databases :
echo mysql_query("USE my_db_name") ; // or mysql_select_db("my_db_name") ;
Then you can make your tables .