473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to create a table from PHP?

mh
Hello,

I'm trying to create a table from a PHP script.
From what I read in my book about PHP and MySQL I

should do something like that:

$sql_query="CREATE TABLE '$num' (
'variable1' mediumint(6) unsigned NOT
NULL,

'variable2' smallint(6) unsigned NOT NULL,
PRIMARY KEY(numero),
)";
First I tried without the 'primary key' and the '' for
the names of the variables. My script was not creating
the table so I decided to add the '' and the "primary
key". It was still not working. Then I've found that
this is working:

$sql_query = 'CREATE TABLE $num ('
. ' `variable1` DATE NOT NULL'
. ' )';

I'd like to know why my first test was not working
(cause it is similar to a listing in a book) and if I
really need (it's related) to use the '.' between each
line of my command?

Another problem is that the table is created with the
name $num and is not replaced like I want by its
value. How can I solve this other problem?

Thanks a lot for your help.

Jul 17 '05 #1
3 2723
On 17 Jul 2005 09:42:34 -0700, "mh" <ma********@gmail.com> wrote:
$sql_query="CREATE TABLE '$num' (


Don't put quotes around identifier names. If you must, then in MySQL use
either ` or ", but not '. ' is for strings, not identifiers.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
mh
Hello,

Andy Hassall a écrit :
On 17 Jul 2005 09:42:34 -0700, "mh" <ma********@gmail.com> wrote:
$sql_query="CREATE TABLE '$num' (


Don't put quotes around identifier names. If you must, then in MySQL use
either ` or ", but not '. ' is for strings, not identifiers.

Ok, but I did that I think. I said in my message that I also tried like
that:
$sql_query = 'CREATE TABLE $num ('
. ' `variable1` DATE NOT NULL'
. ' )';
In this case I don't use the quotes around the name of the table but
MySQL still creates a table called $num and doesn't replace the
variable $num but its value like I wish.

I also tried:
$sql_query="CREATE TABLE $num (variable DATE NOT NULL)";
but without success.
I feel that I tried every possible combiantion without success. There
must be a solution. But what is it?

Jul 17 '05 #3
mh wrote:
Hello,

Andy Hassall a écrit :
On 17 Jul 2005 09:42:34 -0700, "mh" <ma********@gmail.com> wrote:

$sql_query="CREATE TABLE '$num' (


Don't put quotes around identifier names. If you must, then in MySQL use
either ` or ", but not '. ' is for strings, not identifiers.


Ok, but I did that I think. I said in my message that I also tried like
that:
$sql_query = 'CREATE TABLE $num ('
. ' `variable1` DATE NOT NULL'
. ' )';
In this case I don't use the quotes around the name of the table but
MySQL still creates a table called $num and doesn't replace the
variable $num but its value like I wish.

I also tried:
$sql_query="CREATE TABLE $num (variable DATE NOT NULL)";
but without success.
I feel that I tried every possible combiantion without success. There
must be a solution. But what is it?


Look at strings in the PHP manual.

When enclosed in single quotes, variable substitution does NOT take place - so
your table name becomes $num.

When you enclose a string in double quotes, PHP will substitute variables. So
you should have something like:

$sql_query = "CREATE TABLE $num ("
^ ^

Note double quotes instead of single quotes. See
http://www.php.net/manual/en/language.variables.php.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phil Powell | last post by:
create table if not exists nnet_produkt_varegruppe ( nnet_produkt_varegruppe_id int not null auto_increment, primary key(nnet_produkt_varegruppe_id), nnet_produkt_varegruppe_navn varchar(255) not...
6
by: dev | last post by:
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table? please any help? if i have 10 fields in 1 record and...
4
by: Michael Jackson | last post by:
I have a stored procedure to create a table. In my program I want the user to name the table to be created, therefore I pass a parameter to the SP for the table name. I cannot get it to work. It...
7
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...
1
by: poohnie08 | last post by:
i have a excel spreadsheet showing staff name, date,work hour, ot hour, slot1, slot2, slot3, slot4 and others). The "()" will keep repeating from day 1 until end of month. eg in excel spreadsheet,...
24
by: flkeyman | last post by:
Work in legal office. Trying to create solid designed database structure. This is list of tables w/fields and primary keys. Any comments/advice greatly appreciated. tbl-Defendants CaseNumber...
6
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP...
27
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...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
2
by: lakuma | last post by:
Hi, I have a table called A (say) with columns called name, place, animal and thing. I would want to write an on insert trigger on this table, which would create a table with the name of the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.