The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> create a table with $name
xxkasperxx
post 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Apr 12 2012, 01:28 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 4,125
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?


--------------------
"The earth does not belong to us. We belong to the earth."
from Vue du ciel (in French)

"Leave scepticism to others and take action"
from HOME by Goodplanet

An inconvenient truth by Al Gore
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Apr 12 2012, 03:25 AM
Post #3


Jocular coder
********

Group: Members
Posts: 2,212
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.


--------------------
Brian Chandler
Nothing in this post constitutes "commercial solicitation". PayPal does not solicit residents of Japan. Contents may settle in transit. "Legal mind" may or may not be brain-damaged.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Apr 12 2012, 07:56 PM
Post #6


WDG Member
********

Group: Root Admin
Posts: 7,986
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" ...>


--------------------
Darin McGrew
WDG Member since 1998
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xxkasperxx
post 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!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2014 - 12:47 AM