Current location: Hot Scripts Forums » Programming Languages » PHP » creating table in mysql using a script.

creating table in mysql using a script.

Reply
  #1 (permalink)  
Old 04-18-06, 06:48 PM
theecontutor theecontutor is offline
New Member
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
creating table in mysql using a script.

Hi i am trying to create a table using a script. I am new to mysql so i'm not familar with all of the syntax.
Can someone help me with my code. I want to create a table name with space using a script. I can do this using phpmyadmin but i have a lot of tables to create and i would like to use a script.
here's a copy of my code:
PHP Code:
<?
include("dbinfo.php");
mysql_connect(mysql,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$tablename "ECON 1 (Scott) HW";
$query"CREATE TABLE $tablename (time datetime NOT NULL default '0000-00-00 00:00:00', first_name varchar(30) NOT NULL, last_name varchar(30) NOT NULL, email varchar(50) NOT NULL, PRIMARY KEY (time)
)"
;

mysql_query($query);
mysql_close(); 
echo 
"Database created";
?>
any suggestions?

Last edited by Christian; 04-19-06 at 12:31 PM. Reason: Please use [PHP][/PHP] when posting PHP code!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-18-06, 09:28 PM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
You need to put backticks (`) around the table name (it's a good idea to use them all the time even if the name doesn't have spaces).

PHP Code:
$query"CREATE TABLE `$tablename` (
         time datetime NOT NULL default '0000-00-00 00:00:00', 
         first_name varchar(30) NOT NULL, 
         last_name varchar(30) NOT NULL, 
         email varchar(50) NOT NULL, PRIMARY KEY (time))"

The backtick on most keyboards is at the top left, next to the number 1 (it will have ` and ~ on it). Other than that it should be fine.. your MySQL syntax is fine.
__________________
Chris (aka Skeleton Man)
ProgrammingTalk's Perl/PHP Moderator !

Last edited by Skeleton Man; 04-18-06 at 09:33 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get PHP to input data into a MYSQL table? scl789 PHP 5 04-21-05 09:06 PM
Is it possible to lock a MySQL Table? Spreegem PHP 3 02-13-05 01:23 PM
PHP script to modify MySQL Database Diviance Script Requests 3 08-25-04 12:31 PM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
Looking for a update table script thebugz Script Requests 1 12-07-03 06:32 PM


All times are GMT -5. The time now is 06:44 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.