I have a problem creating mySQL tables with PHP. I am making an app
where a user can create a project. Pressing "submit" on proj_form.php
goes to proj_add.php where a couple of things happen. The project's
meta information is put into a project table, mysql_insert_id() gets
the $proj_ID, and a table named that $proj_ID is created to hold all
of that project's tasks. Here is my code to create the table for a
project's tasks:
// 2) Create a table for the tasks of the new project
$sql = "CREATE TABLE $proj_ID (
task_ID int unsigned NOT NULL auto_increment,
task varchar(40),
person varchar(10),
notes varchar(255),
PRIMARY KEY (`task_ID`))";
Here is the error message that creates:
You have an error in your SQL syntax near ' ( task_ID int unsigned NOT
NULL auto_increment, task' at line 1
It has to do with trying to create a table named $proj_ID. How do I
get that to work?
Thanks,
-Andrew 3 3579
Message-ID: <42**************************@posting.google.com > from Andrew
contained the following: It has to do with trying to create a table named $proj_ID. How do I get that to work?
The SQL is fine. Try echoing the SQL to make sure $proj_ID has a value.
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
"Andrew" <ak****@web4000.com> wrote in message
news:42**************************@posting.google.c om... I have a problem creating mySQL tables with PHP. I am making an app where a user can create a project. Pressing "submit" on proj_form.php goes to proj_add.php where a couple of things happen. The project's meta information is put into a project table, mysql_insert_id() gets the $proj_ID, and a table named that $proj_ID is created to hold all of that project's tasks. Here is my code to create the table for a project's tasks:
// 2) Create a table for the tasks of the new project $sql = "CREATE TABLE $proj_ID ( task_ID int unsigned NOT NULL auto_increment, task varchar(40), person varchar(10), notes varchar(255), PRIMARY KEY (`task_ID`))";
Here is the error message that creates: You have an error in your SQL syntax near ' ( task_ID int unsigned NOT NULL auto_increment, task' at line 1
It has to do with trying to create a table named $proj_ID. How do I get that to work?
Thanks, -Andrew
I'm just as new but I believe what I've done below should work
$sql = "CREATE TABLE $proj_ID (
task_ID int NOT NULL auto_increment,
task varchar(40),
person varchar(10),
notes varchar(254),
PRIMARY KEY ('task_ID'))";
First off - I believe 'int' is unsigned automatically - and I'm more
definite of this since its an auto_increment column so I removed the
"unsigned" piece that you had.
Second - notes is too long - I think 254 is the maximume for varchar (since
zero is a number) - remember, you could always use TEXT - meaning changing
your notes entry to
notes TEXT,
from
notes varchar(255),
Third - you had the wrong hooks on your PRIMARY KEY - they should be
aposrtaphes (meaning ') and not hooks (meaning not `)
Again - I'm learning MySQL too - but give that a try...
On 6 Sep 2003 19:40:58 -0700, ak****@web4000.com (Andrew) wrote: I have a problem creating mySQL tables with PHP. I am making an app where a user can create a project. Pressing "submit" on proj_form.php goes to proj_add.php where a couple of things happen. The project's meta information is put into a project table, mysql_insert_id() gets the $proj_ID, and a table named that $proj_ID is created to hold all of that project's tasks. Here is my code to create the table for a project's tasks:
Avoid doing this. Don't create tables on the fly. Just add proj_id to the
primary key of a single Task table.
// 2) Create a table for the tasks of the new project $sql = "CREATE TABLE $proj_ID ( task_ID int unsigned NOT NULL auto_increment, task varchar(40), person varchar(10), notes varchar(255), PRIMARY KEY (`task_ID`))";
Here is the error message that creates: You have an error in your SQL syntax near ' ( task_ID int unsigned NOT NULL auto_increment, task' at line 1
It has to do with trying to create a table named $proj_ID. How do I get that to work?
You've used `` backticks on the task_ID in the primary key - only use them
when you have very bad column names, e.g. containing spaces or weird
characters. They should never be necessary. Isn't the problem though.
The following works OK:
mysql> CREATE TABLE proj_ID (
-> task_ID int unsigned NOT NULL auto_increment,
-> task varchar(40),
-> person varchar(10),
-> notes varchar(255),
-> primary key (task_ID)
-> );
Query OK, 0 rows affected (0.00 sec)
What does $proj_ID contain? Are you sure it's correct?
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) ( http://www.andyh.co.uk)
Space: disk usage analysis tool ( http://www.andyhsoftware.co.uk/space) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sangbae |
last post by:
I cannot create table using adodbapi.
I have no problem with SELECT etc.
But I can create table using win32com.client directly.
I don't know why.
Could you give some advice, please?
This...
|
by: Guy Deprez |
last post by:
Hi,
i'm having a problem to create indexes.
STEP 1
-----------
Connection is OK (you can find the string at the end of the message)
Table ("Couleurs") creation is OK
STEP 2. Index Creation
|
by: Lauren Quantrell |
last post by:
Is there a way to create a text file (such as a Windows Notepad file)
by using a trigger on a table? What I want to do is to send a row of
information to a table where the table: tblFileData has...
|
by: Karen Sullivan |
last post by:
Hi, all. I'm fairly new to SQL, and I have been trying to create a table
from a text file. I have been looking at this for days, and can't find the
problem. I get a syntax error " Line 55:...
|
by: Wolfgang Kreuzer |
last post by:
Hello all,
I have two tables - Projects and ProjectStruct
Table Projects contains master records of the projects, ProjectStruct
allows to define a project herarchie and contains the fields...
|
by: YONETANI Tomokazu |
last post by:
Hello.
After upgrading a test database to V8.2 with FixPak7a, too see if
the production servers can be safely upgraded, I noticed that inserts
on an insertable view which consists of multiple...
|
by: Jacob |
last post by:
A simple question:
I've read a couple of things that indicates I can create a new table in my
database using some SQL command. Is this correct? I would like to load a
database into a DataSet,...
|
by: max |
last post by:
Hello,
I am a newbye, and I'm trying to write a simple application.
I have five tables with three columns; all tables are identical; I need to
change some data in the first table and let VB...
|
by: raylopez99 |
last post by:
Keep in mind this is my first compiled SQL program Stored Procedure
(SP), copied from a book by Frasier Visual C++.NET in Visual Studio
2005 (Chap12). So far, so theory, except for one bug...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |