The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
creating a table/getting error
Discuss creating a table/getting error in the MySQL Help forum on Dev Shed. creating a table/getting error MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 24th, 2000, 10:40 PM
|
|
Junior Member
|
|
Join Date: May 2000
Posts: 14
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 . " " . "dow$i" . " " . "VARCHAR (9)," . " " .
"max$i" . " " . "TINYINT," . " " .
"min$i" . " " . "TINYINT," . " " .
"sky$i" . " " . "VARCHAR (20)," . " ";
endfor;
$stmt = $one . " " . "fcstdays" . " " . "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
|

May 25th, 2000, 06:37 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
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..."
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|