Syntax problem in PHP table creation

This is a discussion on "Syntax problem in PHP table creation" within the Databases section. This forum, and the thread "Syntax problem in PHP table creation are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 16th, 2006, 15:05
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Syntax problem in PHP table creation

Code: Select all
function Create_Table($testname, $answerarray)
        {
        $sql = "CREATE TABLE $testname (  id SMALLINT(5) NOT NULL AUTO_INCREMENT,  name varchar(30), score int,  PRIMARY KEY (id), UNIQUE id (id))";
        $result = mysql_query($sql) or die("Cant create table: ".mysql_error());
        $numberofquestions = count($answerarray);
        for($i=1 ;$i<=$numberofquestions ; $i++) {

                $newfieldname="q$i";
                $sql = "alter table $testname add column $newfieldname tinyint(1)";
                $result = mysql_query($sql) or die("Cant update table: ".mysql_error());
                }
        }
I'm getting this error message:

Quote:
Cant create table: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( id SMALLINT(5) NOT NULL AUTO_INCREMENT, name varchar(30), score int, PRIMAR' at line 1
Reply With Quote

  #2 (permalink)  
Old May 17th, 2006, 21:53
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Syntax problem in PHP table creation

I think your field names need to be inside quotes.
Reply With Quote
  #3 (permalink)  
Old Jun 18th, 2006, 22:58
Junior Member
Join Date: Jun 2006
Location: Wisconsin
Age: 30
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Syntax problem in PHP table creation

echo out $sql and see what it looks like.
Reply With Quote
  #4 (permalink)  
Old Jul 10th, 2006, 18:50
Junior Member
Join Date: Jul 2006
Location: Bracknell
Age: 28
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Syntax problem in PHP table creation

If your value for $testname is null then this is the exact error message you get.

Are you sure a valid value is being passed to the function ?
Reply With Quote
  #5 (permalink)  
Old Jul 13th, 2006, 22:27
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Syntax problem in PHP table creation

This has been on the back burner while I studied up on php/sql, hehe. I'll have a look at the replies, thanks everyone for trying to help.
Reply With Quote
Reply

Tags
syntax, problem, php, table, creation

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Syntax problem -- object has no properties dsmithhfx JavaScript Forum 6 Jan 19th, 2008 19:30
Table conversion problem dartiss Web Page Design 9 Jul 26th, 2006 17:42
Table Problem? ivan Web Page Design 8 Mar 1st, 2006 09:31
Mysql syntax problem... ktsirig Databases 1 Jan 6th, 2006 15:51
CSS and Table problem lisnalinchy Web Page Design 10 Aug 3rd, 2005 09:54


All times are GMT. The time now is 07:21.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43