Jump to content

create table issues


littletechie

Recommended Posts

Hello everyone

 

I'm setting up an admin interface for specified users to be able to create/delete tables as they please.

 

To create a table, all they have to do is type in a table name then click 'Create'.  Which will then run the script (which seemed pretty straightforward) to create the table in the database.

 

Here is the code I have, but I keep err-ing out on the query and I have run out of ideas as to what could be the problem.

 

<?php

 

#variables

$tname = $_POST['table'];

 

 

#connect to mysql

$conn = @mysql_connect("localhost", "root", "tracer1") 

or die("Err:Conn");

 

 

#select db

$rs = @mysql_select_db("test", $conn) 

or die("Err:Db");

 

#create table

$result="CREATE TABLE $tname (

FirstName VARCHAR(25),

LastName VARCHAR(25),

address VARCHAR(25),

city VARCHAR(25),

state VARCHAR(25),

zip VARCHAR(25),

phone VARCHAR(25),

email VARCHAR(25)

#role VARCHAR(25)

)";

 

 

#execute query

$rs = mysql_query($result, $conn)

or die ("Err:Query");

 

if($rs){

echo("$table was successfully created!");

}

 

?>

 

 

Any thoughts on this would be greatly appreciated  :)

Link to comment
https://forums.phpfreaks.com/topic/160144-create-table-issues/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.