SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: create table error
-
Jun 20, 2003, 05:33 #1
create table error
Hello
I am trying to create a table using the code below and am getting the error:
Datbase ERROR: CREATE TABLE links ( id INT NOT NULL AUTO_INCREMENT, sitename VARCHAR(50), siteurl VARCHAR(75), description TEXT, category VARCHAR(50), PRIMARY KEY(id) );
You have an error in your SQL syntax near '; ' at line 1Create Table Results RESULT =
Any ideas as to what the problem is?
<?
$usr = "mancroft";
$pwd = "xxxxxxxx";
$db = "mancroft_linksdb";
$host = "localhost";
/*== CONNECT TO DATABASE ==*/
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { print "ERROR: " . mysql_error() . "\n"; }
#select database to use
mysql_select_db($db, $cid);
/*== SETUP SQL STATEMENT ==*/
# create links table
$sql = " CREATE TABLE links (";
$sql .= " id INT NOT NULL AUTO_INCREMENT, ";
$sql .= " sitename VARCHAR(50), ";
$sql .= " siteurl VARCHAR(75), ";
$sql .= " description TEXT, ";
$sql .= " category VARCHAR(50), ";
$sql .= " PRIMARY KEY(id) ";
$sql .= " ); ";
/*== EXECUTE SQL STATEMENT ==*/
$result = mysql_query($sql, $cid);
if (mysql_error()) { print "Datbase ERROR: $sql <br>" . mysql_error(); }
# display result for table creation query
# this should be 1 on a success
print "Create Table Results RESULT = $result\n\n";
?>:
:
-
Aug 6, 2003, 08:57 #2
- Join Date
- Mar 2003
- Location
- Nebraska
- Posts
- 86
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Odd, I cut and pasted your code and only changed the username/password/db and it worked just fine on my system. Also, one note on the sql statement which might make it easier to read.
PHP Code:<?php
$sql = "
CREATE TABLE garlinks (
id INT NOT NULL AUTO_INCREMENT,
sitename VARCHAR(50),
siteurl VARCHAR(75),
description TEXT,
category VARCHAR(50),
PRIMARY KEY(id)
);
";
-
Aug 6, 2003, 21:28 #3
- Join Date
- Jul 2003
- Location
- Palo Alto
- Posts
- 179
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I wouldn't think this would cause such an error (rather, I would think it would be ignored), but you don't need the semi-colon at the end of your SQL statement when running it from PHP. Other than that I'm not seeing anything strange.
-
Aug 7, 2003, 06:07 #4
- Join Date
- Jul 2003
- Location
- Missouri
- Posts
- 127
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think you need a semicolon after the last entry like this:PRIMARY KEY(id);
After the third time of reading the instructions,
it finally soaks in to my thick skull.
Bookmarks