MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 24th, 2000, 10:40 PM
bvrtrimmer bvrtrimmer is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 14 bvrtrimmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here is the error I get:


Error in executing CREATE TABLE %s (cityname VARCHAR (20), KEY index_name
(cityname(10)), dow1 VARCHAR (9), max1 TINYINT, min1 TINYINT, sky1 VARCHAR (20), fcstdays TINYINT)
stmt

error: 1064 You have an error in your SQL syntax near ' dow1 VARCHAR
(9), max1 TINYINT, min1 TINYINT,&nbs' at
line 1


Here is the actual code for this page:

<?php



require ("common.php3");

//CREATE TABLE STATEMENT BASED ON NUMBER OF FORECAST DAYS


$one = "CREATE TABLE %s (cityname VARCHAR (20), KEY index_name (cityname(10)),";

for ($i = 1; $i <= $fcstdays; $i++):
$one = $one . "&nbsp;" . "dow$i" . "&nbsp;" . "VARCHAR (9)," . "&nbsp;" .
"max$i" . "&nbsp;" . "TINYINT," . "&nbsp;" .
"min$i" . "&nbsp;" . "TINYINT," . "&nbsp;" .
"sky$i" . "&nbsp;" . "VARCHAR (20)," . "&nbsp;";
endfor;

$stmt = $one . "&nbsp;" . "fcstdays" . "&nbsp;" . "TINYINT" . ")";


$hostName ="xxxx";
$userName ="xxxx";
$password ="xxxx";
$databaseName ="xxxx";

//FUNCTION TO CREATE ERROR MESSAGE

function printError ($errorMesg)
{
printf("<BR> %s <BR>n", $errorMesg);
}

// OPEN CONNECTION WITH THE DATABASE SERVER

if (!($link=mysql_connect($hostname, $userName, $password))) {
printError(sprintf("error connecting to host %s, by users %s", $hostName, $userName));
exit();
}

// SELECT THE DATABASE

if (!mysql_select_db($databaseName, $link)) {
printError(sprintf("Error in selecting %s database", $databaseName));
printError(sprintf("error:%d %s", mysql_errno($link), mysql_error($link)));
exit();
}

// CREATE THE TABLE

if (!mysql_query(sprintf($stmt,$tablename), $link)) {
printError(sprintf("Error in executing %s stmt", $stmt));
printError(sprintf("error: %d %s", mysql_errno($link), mysql_error($link)));
exit();
}

printf("<BR> Created Table %s.%s <BR>n", $databaseName, $tablename);

?>

Any idea?, somebody help, been stearing at screen for hours now

Reply With Quote
  #2  
Old May 25th, 2000, 06:37 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

first of all you can't give table name with '%s' value.

and cityname should be NOT NULL field becoz that is unique or index field.


your query should be something like this..


CREATE TABLE test(cityname VARCHAR (20)not null, KEY index_name
(cityname(10)), dow1 VARCHAR (9), max1 TINYINT, min1 TINYINT, sky1 VARCHAR (20), fcstdays TINYINT);

just create a query like above with concatenation.




------------------
SR -
shiju.dreamcenter.net

"The fear of the LORD is the beginning of knowledge..."

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > creating a table/getting error

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap