Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Create DB Table


how to create a table in a SQL database using PHP3. I can login via telnet and create a table but that is sorta worthless considering that I'd like to be able to do it via a browser instead. Would someone please post some quick code to point me in the right direction?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Create Table Using PHP
use mysql_query ? what's the parameter of string query ?

SQL Create Table From Pdf
I would like to use a routine which has as input a pdf form file and returns
the SQL statement to create the table for a SQL database.

Did someone know such a tool?

CREATE Table With PHP Script
I'm trying to write a PHP script that will create tables, so I'm working of a test script at the moment and I've been trying to use some code from a phpBB script to do this as while mysql has a nice mysql_create_db function they have no create_table function, not that I can find anyway.
I can't find a similar problem from searching here either :-(

The code I'm using is below...

<?php
include ("../cgi-bin/connect.inc");
$tables = array ("test" => "CREATE TABLE test (
testing varchar(20),
)");
$result = mysql_query($tables);
if ($result) {echo "YEY";}
else {
echo("<P>Error: " .
mysql_error() . "</P>");
exit(); }
?>

and it returns this...

Error: You have an error in your SQL syntax near 'Array' at line 1

Something simpler such as

<?php
include ("../cgi-bin/connect.inc");
CREATE TABLE test (
country varchar(40) NOT NULL,
UNIQUE country (country)
);
?>

just gives an error on the 3rd line

If anyone can point me in the right direction as to how to create tables with PHP scripts, which I know must be possible as phpBB manages fine.

How To Create A MySQL Table With PHP?
How to create a MySQL table with PHP?

MySQL Table Create
Here is the code I'm trying to create the database with (I'm using phpMyAdmin so I just select the file I want to use and press submit and it creates the tables).

CREATE TABLE bips (
banned_ip varchar(15) NOT NULL);

CREATE TABLE messages (
entry_id double(16,4) DEFAULT &#390;.0000' NOT NULL auto_increment,
name varchar(25) NOT NULL,
email varchar(35) NOT NULL,
icq int(11) NOT NULL,
http varchar(50) NOT NULL,
message mediumtext NOT NULL,
when int(12) NOT NULL,
ip varchar(15) NOT NULL,
UNIQUE entry_id (entry_id),
PRIMARY KEY (entry_id));

------------------------
phpMyAdmin gives me an error with that, (none of those tables exists btw)... the error is

MySQL said: You have an error in your SQL syntax near 'when int(12) NOT NULL, ip varchar(15) NOT NULL, UNIQUE entry_id (entry_i' at line 8 .

CREATE TABLE Problem
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?

Create Mysql Table
I'm trying to create a mysql table in php. i have no problems doing a select, insert or anything else. i just don't know what the proper code is to create a table if it even exists.

Create & Populate Table?
I am trying to do two things with one form:

1. Create a table in a MySQL database
2. Populate it at the same time

So far I have been able to create it, but the population isn't going so well. Here is the basic code I am using. PHP Code:

Why Doesn't My Create Table Work
with the following script to create a table:

Create Table From Variable
I need to know, how I can to do to create a table in PHP, taking de
name for this table from a form variable.

Create A New Table Automatically
How do i create a new table automatically using php code in a script ?

Create A One Column Table
Using the following code, how do I create a one column table, with "Firstname, Lastname & Sex" as the heading.

Also, how do I display the row data (i.e Firstname etc) using the following format?: Code:

Create Html Table With Php Result?
I'm looking to display 5 records in one rows, from the database. What i mean is, basically, let's take the "emails" as an example. I have a table with 100s of email
addresses. Now i want to display these email addresses on a html table, but i want to display only 5 email adresses per table row, then the next 5 in the next table row and so
on.

Create A Table Regarding A Text File
I have this .txt file :

Roger|tow25$rank259
Isabelle|tow36$rank24
Pascal|tow12$rank29
Sergeï|tow45$rank5
Michel|tow1245$rank45478
Frédéric|tow1$rank125425

And this programm php3
<?php
$fichier = "classeur.txt";
if($fp = fopen($fichier,"r")){
$ligne=1;
echo "<table border=1 bordercolor="#00CCFF" width=500>
";
echo "<tr align=center><td colspan=3>TITRE</td>";
while (!feof($fp)) {
list( $name, $tampon ) = explode( "|tow", $fp );
list( $tow, $obj ) = explode ( "$rank", $tampon );
echo " <tr>";
echo "<td
align=center><b>Nom".$name."</b></td><td>Tow".$tow."</td><td>Obj".$obj."</td[color=blue]
>";[/color]
echo "</tr>
";
$ligne++;
echo "</table>
";
echo "$cell";
fclose($fp);
}else{
echo "Error : open impossible ".$fichier;
exit();
}
?>

I would like to past each value of the lines in the tex file, in 3 variables
$nom; $tow; $obj
and create a table with 3 column ( column 1 the name, in 2 the tow, and in 3
the obj)

Editor To Create Table From MySQL
Does anyone know of a Windows editor I can use to design a table from
a MySQL database?

I have a end-user catalog I need to create. Nothing fancy - just
display a few fields. I could hand code it, but do not have the time
to relearn all the sql. No shopping-cart or anthing, just display
fields.

Urgent: Create Table If It Doesn't Exist?
I'm using a script what inserts data into a table (called "_$this" - e.g. "_2") like the following: Code:

mysql_query("insert into _$this->uid (time,referer) values ('".time()."','$this->referer2'");

I need to check if the table "_$this" exists before inserting data and if it doesn't exist i'd like to create this table before inserting it like: Code:

mysql_query("CREATE TABLE _$this (definitions)");

Means in simple steps:

1. Check if table exists - if yes -> step 3, if no -> step 2
2. Create table -> step 3
3. Insert data

Any code snippet for a php-newbie like me?

Create A Table From A Mysql Query
How would you create a table from a mysql query, but limit the amount of values on each row.

Row Size Error On Create Of Table
I have a table that already exists in MySQL, and I want to add it to another database - but this time defined with the UTF-8 charset. This is part of some preparation to move from the default lation1 to utf8.

I have exported my existing table to a .sql file and changed the latin1 reference to utf8. But when I run the SQL script to create the table in my other database it generates a row size error. Code:

Create A Table In MySQL From A .php File
Is it possible to create a mySQL table from a .php file? If so how?

Create A Dynamic Table Javascript?
I have picture section where users can upload pictures to my website and I have created a basic way viewing these pictures but this is not astheticaly pleasing. So i was wondering if i could populate a html table with these pictures.

The way this system works is that it uses a while loop that brings the date, url and also who uploaded the picture into the page. I was wondering if this information could be put into a table but i cannot see a way. Code:

Dynamically Create Table Rows As Needed
I have a form with a table. Each table row has a ID= "some number". I have 4 rows and might need to create more. how can i do this in php? To go along with this, When I hit the submit buton, I then need all the table row data saved to a db i have. I can insert 1 line with out a issue. I also made sure the table row name="" fields are unique. ex. Code:

Create A Link In A Table From Echo 'ed Sql Data
im using the following code to output everything in a database table under headings in an html table untill theres no more data left. The headings are things like name address etc.

could i make it so when all the data is shown each name or ID becomes a link and when clicked takes the user to a more detailed page on the selected client.

because of the way the table is generated there is no where to place link tags. is there a more appropriate way that is more editable?

it would be nice to have checkboxes at the edge of each customer also to enable a complete status or deleting a client from the table. Code:

Create A Data Entry HTML Form For Given Table
I am working on a simple web site updating utility for a web site. Rather than hard code the data entry forms, I would like to automactically generate them based upon the table a user selects to update or insert into. What is the best way to approach this?

for "insert" should I use the MySQL DESCRIBE table command and build a form element for each field according to its data type? for "update" should I use the DESCRIBE command to build the form as above and SELECT statement to populate each element with data, or should I just use a SELECT statement to retrieve the data and use php to determine the field type and choose an appropriate form element?

Create A Button To Export A Mysql Table To An Excel File.
Does anyone have the code that creates a link, and on click, takes a specified table in my database and exports and downloads an excel file?

Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?

Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for.  Can anyone help me get the Agreed? table's background color to the colors above? Code:

Outputting A Table Or Form Using SHOW FIELDS FROM Table
In the code the MySQL database was queried using "SHOW FIELDS FROM table" which and the returned results of column names was then use to build an output for a form and a table with php using a series of if statements along the lines of if the returned field name matches something echo a text input field.

I have never seen this done this way before, so I want to get the opinion of the devshed user. Does it seem like an unsual long process to build up a form. Is there a security advantage doing it this way? Has anyone ever done it this way before?

Finding Matches In A Table And Then Moving That Match To Another Table?
Ok, I have a database that has a table called critiera in this table
is to fields on is ID and the other is critiera.

Now I want to filter out all the one that don't apple to the list and
move the one that match to a different database.

I know how to open a connection, close, select

but I don't know how I would inside of a database use another one as
the way to create the list of critieras....

Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias'
the mysql_fetch_field function returns a value $result=>table which
will contain the alias, not the actual table name.
Is there a way to get the actual table name ?

I am running mysql 4.1 and php 4.4

Grab Data From A Table, Echo, Then Insert It Into A New Table...
I'm trying to do is count the number of times usernames shows up in a table. I then want to reinsert that information into a different table with the Username in column1 & the occurrences in column2 for every user that is echoed on the page. Code:

Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'.

There is one of each item in products and each product has it's own unique 'prodno'

There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example:

id = 1
prodid = 7001
qty = 300
price = 12.5

id = 2
prodid = 7001
qty = 400
price = 15.5

I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table.

Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item..

This is all very confusing to me, and I'm the one writing it. Let's try one last time..

Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.

Update Table While Insert Data To Another Table
it seem like mine coding din work.
[php]<?

include("checkin.html");
$conn=mysql_connect('localhost','root','') or die ('Could not connect to server');
$today = date("Y.m.d");
mysql_select_db('hms', $conn);

$ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn);

if( $ok ){

$up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID');

if(mysql_affected_rows( $up ) == 1)
{
echo'Checked IN!'
}else { echo'No such student to check in' }}
else { echo'Check In FAILED, please check again'}?>[php]

How To Transfer A Data With An Id To Another Table From A Table?
how am i going to transfer let say a name identified using the suer id and copy the name to the other table having the same user id>?

How Can I Find A Name From One Table In A Text From Another Table?
I have one table with a description field and other info, and I also have another table with a list of names and picture url:s. When I display the text description on my site I'd like to know if there are a match with a name from the 'names' table in the text. Code:

Returning Table Name As Well As Fields From That Table
I am returning all fields from news and from regional, however I want to determine where the fields have come from when I ouput the data, therefore I need to return the table name with the fields. Is this possible? Code:

Moving Data From One Table To Another Table
Does anyone know how to move one row from a table in a mysql database to another table using php?

Move Table Row To A New Table
I have a database of some information and it is in a table row by row.

I have a page that displays these in a table row by row, however I want to have a link to the side of each row allowing me to transfer that row to a new table.

How would I do this? I've tried a few ways but that was a random guess and didn't work.

Create Rss Xml
I'm currently working on creating the xml feed since I had data ready
in my database after web data extraction. However, it has errors for
this line:

<xml version="1.0" encoding="ISO-8859-1">

I was unable to solve this.

<html>
<head>
<title>MMU RSS FEED</title>
</head>
<body>

header("Content-type: application/xml");

<xml version="1.0" encoding="ISO-8859-1">

<rss version ="2.0">

<channel>
<title>MMU RSS FEED Today: <?php echo date("D, d-M-Y H:i:s")?></
title>
<link>http://bulletin.mmu.edu.my/</link>
<description>MMU RSS FEED</description>
<ttl>60<ttl>

<?php

//connect to database
$db = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("bulletin", $db) or die(mysql_error());

$day = date("Y-n-j");

//select queries
$sql = "SELECT * FROM `bul_data` WHERE `DATE` LIKE '{$day}%' ORDER by
`DEPARTMENT`";
echo "sql=".$sql;

$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res)>0)
{

while($row=mysql_fetch_assoc($res))
{
$date = $row['DATE'];
$title = $row['TITLE'];
$department = $row['DEPARTMENT'];
$link = $row['LINK'];

//output to browser

echo "<item>";
echo "<title>$title</title>";
echo "<category>$department</category>";
echo "<link><a href="$link">$link</a></link>";
echo "</item>";

}

echo "</table>";

}

?>

</channel>
</rss>
</body>
</html>

Create Php.ini
The support of hosting contracted indicates that I
must create a file php.ini in the folder wwwroot/in
which I indicate the new directors for the values of
upload_max_size, memory_limit, post_max_size,
max_input_time, max_execution_time to me which I need.
Using the function ini_set. The truth I have proven of
many forms and it does not manage to do it if somebody
knows to use this function or similar configuration I
thank for them.

Help Need To Create Pdf
I want to create pdf files on fly. Is there any class is available?

Can Php Create A New Txt File?
I'm trying to build an e-card page for a client using php, but they don't want to use a mySQL database, so I was wondering if PHP can create new text files when someone enters their information into a form and then the recipient gets an email with that txt file reference in a link and can then go to a page that populates with that particular text.

Does it sound like I'm on the right path?

PHP Create .htaccess
Can PHP create a .htaccess file?

Using Php To Create Subdomains
Hi i was interested in knowing if php can be to create subdomains and if so can someone point me in that direction.

Create Directories On The Fly...
Just curious to know is it possible to create directories on the fly?

What I have done is created a script when you can add categories and subcategories, but what I would like to do is create a directory physcially within that category. For instance using the mkdir command using linux. In a way traversing through and creating a directory.

An example would be:

If I created a category called business and econony then it would display this in the address bar.

http://www.domain.com/Business_and_Economy

Then perhaps under Business and Economy, a category called Accounting, then it would display the following:

http://www.domain.com/Business_and_Economy/Accounting/

Hopefully I'm making some sense here.

Heres the code:

function maketree($rootcatid,$level)
{
$sql="select catid,cat_name
from quiz_category
where parentid=$rootcatid
order by cat_name";

$result=mysql_query($sql);

while (list($DBcatid,$DBcatname)=mysql_fetch_row($result))
{
$width=($level+1)*24;
$display="<img src=http://www.domain.com/spacer.gif border=0 width=$width height=12>";
if ($DBcatid==1)
{
$display.="<input type="radio" name="quest_type" value=$DBcatid checked>";
}
else
{
$display.="<input type="radio" name="quest_type" value=$DBcatid>";
}
$display.="$DBcatname<br>
";
echo $display;
maketree($DBcatid,$level+1);
}
}

if ($submit=='Add New Category')
{
if ($new_cat!='')
{
mysql_query("insert into quiz_category
(parentid,cat_name) values ($quest_type,'$new_cat')");

# need to create directory here

echo "<br><br><center><b>New category entered</b></center>";
}
else
echo "<br><br><center><b>New category name must be entered</b></center>";
}

Using Php To Create .htaccess
if you have a form with two variables, USER and PASS, how do you encode them to the format for a .htaccess password protection file?

Cannot Create A URL With Two Variables
I wish to create a url with two variables from data passed from a previous page. If I allocate text to the variables on the page, like

$linkaddress = (&#391234;');
$clientsemail = ('olympic@mechan.freeserve.com');

the full correct URL is echoed back thus

http://www.morgle.com/mymorglemailer.php?mylinkaddress=1234&calledemailaddress=olympic@mechan.freeserve.com

However, if I try and create the URL with the variables posted from the previous page , the URL is truncated after the first variable thus

http://www.morgle.com/mymorglemailer.php?mylinkaddress=1234

I know the variables being posted from the previous page contain data because I have echoed them back seperately ok.

Create A Timestamp
I have a date YYYY/MM/DD and a houte HH:MM and want to create a timestamp
from it. The date is easy but how do I add the time?

Create FTP Account
It's there any way to create a FTP account with PHP?

Create New Line
I am not sure I post to correct forum or not, anyway, my question is

I create some textfield in tabular format (in loop 10 times). Now I want
to add function "add new line" where I click ADD, it will create new text
field shown in the form, is it possible to do?


Copyright © 2005-08 www.BigResource.com, All rights reserved