create a table with $name |
create a table with $name |
xxkasperxx |
Apr 11 2012, 10:06 PM
Post
#1
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
I am trying to create a new table using a form like this
CODE <form action='' method="POST"> Name: <textarea rows="1" name="name" class="style"> </textarea><br> Percent: <textarea name="name" class="style">0%</textarea> <br> <input type="submit" name="add" value="ADD New User"> </form> and my php: CODE $name = $_POST['name']; if ($_POST) { mysql_query("CREATE TABLE '$name'( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT)") or die(mysql_error()); } but i get this error "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 ''0%'( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), ' at line 1" How do i fix that? |
Frederiek |
Apr 12 2012, 01:28 AM
Post
#2
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
You use name="name" twice and the second one is taken in account by your script:
Name: <textarea rows="1" name="name" class="style"> </textarea><br> Percent: <textarea name="name" class="style">0%</textarea> BTW, why don't you use single line text fields? |
Brian Chandler |
Apr 12 2012, 03:25 AM
Post
#3
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
Anyway, you are trying to create a new table for each user. This means you have misunderstood the whole point of a relational database, and like the other questioner in this forum you need to go back to the beginning and read a tutorial or real book.
In any event trying to create tables with random names will never work because of characters that need escaping, or tables that already exist for genuine purposes. |
xxkasperxx |
Apr 12 2012, 06:59 PM
Post
#4
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
They are only created by me. I see no point if I already know what is in the database or not.
|
xxkasperxx |
Apr 12 2012, 07:00 PM
Post
#5
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
Frederick what do you mean? I have never herd of them in the html or php books I have read.
|
Darin McGrew |
Apr 12 2012, 07:56 PM
Post
#6
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
From our HTML Reference:
http://htmlhelp.com/reference/html40/forms/input.html "The type of form control defined by INPUT is given by the TYPE attribute. The default TYPE is text, which provides a single-line text input field." A single-line text field is just: <input type="text" ...> |
xxkasperxx |
Apr 12 2012, 08:11 PM
Post
#7
|
Serious Coder Group: Members Posts: 261 Joined: 30-April 11 Member No.: 14,449 |
Thank you for the quick reply!
|
Lo-Fi Version | Time is now: 19th April 2024 - 06:03 AM |