[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 12-30-2006, 07:52 PM   #1 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


MYSQL error

hey
i am getting this error:
Code:
Documentation
#1064 - 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 'CREATE TABLE `messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from` varchar' at line 7
for this MYSQL :
PHP Code:
CREATE TABLE `keys` (
`
user_id` int(11) NOT NULL AUTO_INCREMENT,
`
key` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY  (`user_id`)
)
ENGINE=MyISAM DEFAULT CHARSET=latin1

CREATE TABLE
`messages` (
`
id` int(11) NOT NULL AUTO_INCREMENT,
`
from` varchar(255) NOT NULL DEFAULT '0',
`
to` varchar(255) NOT NULL DEFAULT '0',
`
message` longtext NOT NULL,
`
title` varchar(255) NOT NULL DEFAULT '',
`
time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`
read` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY  (`id`)
)
ENGINE=MyISAM DEFAULT CHARSET=latin1

CREATE TABLE
`users` (
`
id` int(11) NOT NULL AUTO_INCREMENT,
`
username` varchar(255) NOT NULL DEFAULT '',
`
password` varchar(32) NOT NULL DEFAULT '',
`
name` varchar(255) NOT NULL DEFAULT '',
`
email` varchar(255) NOT NULL DEFAULT '',
`
ip` varchar(255) NOT NULL DEFAULT '',
`
admin` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY  (`id`)
)
ENGINE=MyISAM DEFAULT CHARSET=latin1
can anyone help me out? thanks
unknowngiver is offline  
Old 12-31-2006, 05:59 AM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
if you are trying to execute all 3 together which it looks like you are you need to put a ; after each query:-

PHP Code:
 CREATE TABLE `keys` (
`
user_id` int(11) NOT NULL AUTO_INCREMENT,
`
key` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY  (`user_id`)
)
ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `messages` (
`
id` int(11) NOT NULL AUTO_INCREMENT,
`
from` varchar(255) NOT NULL DEFAULT '0',
`
to` varchar(255) NOT NULL DEFAULT '0',
`
message` longtext NOT NULL,
`
title` varchar(255) NOT NULL DEFAULT '',
`
time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`
read` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY  (`id`)
)
ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `users` (
`
id` int(11) NOT NULL AUTO_INCREMENT,
`
username` varchar(255) NOT NULL DEFAULT '',
`
password` varchar(32) NOT NULL DEFAULT '',
`
name` varchar(255) NOT NULL DEFAULT '',
`
email` varchar(255) NOT NULL DEFAULT '',
`
ip` varchar(255) NOT NULL DEFAULT '',
`
admin` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY  (`id`)
)
ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
This is so mysql can distinguish between each sql statement, if you do not do this it thinks it is just 1 statement.
Peter is offline  
Old 12-31-2006, 06:29 AM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
 
Join Date: Aug 2005
Location: Web 1.0
Posts: 6,285
1,095.94 NP$ (Donate)

sdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond repute

Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer
Quote:
Originally Posted by unknowngiver
hey
i am getting this error:
Code:
Documentation
#1064 - 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 'CREATE TABLE `messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from` varchar' at line 7

FROM is a reserved keyword in SQL.
Avoid using reserved keywords in field names or expressions and you'll be fine
__________________
Buy now - MassDeveloper.com $500
sdsinc is offline  
Old 12-31-2006, 09:29 AM   #4 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Quote:
Originally Posted by sdsinc

FROM is a reserved keyword in SQL.
Avoid using reserved keywords in field names or expressions and you'll be fine
It isn't that causing the problem. Run it through mysql and you will see they work when you do them separately but when together it fails because of the missing ;

The following is taken from THIS page from the mysql manual:-

Quote:
A common problem stems from trying to use an identifier such as a table or column name that is a reserved word such as SELECT or the name of a built-in MySQL data type or function such as TIMESTAMP or GROUP.

Reserved words are permitted as identifiers if you quote them as described in Section 9.2, “Database, Table, Index, Column, and Alias Names”
In other words if you use the ticks around the field name as the op has already done.

Last edited by filth@flexiwebhost; 12-31-2006 at 09:38 AM.
Peter is offline  
Old 12-31-2006, 07:40 PM   #5 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold


yup i ran it seprately and worked fine thanks
unknowngiver is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:27 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85