Log in

View Full Version : Create New Table



onestopplay
07-01-2009, 11:00 AM
So I have a Form:

<form action="createtable.php" method="post"
Table Name: <input type="text" name="table"><br>
<input type="submit" name="submit" value="submit">
</form>

I want this to create a table in my MySQL database. Possible?
I have googled and come up with nothing.

heavensgate15
07-01-2009, 12:47 PM
Yup, it's possible to create a table through php script... try this:




<html>
<head>
<title></title>
</head>

<body>

<form action="" method="post">
Table Name: <input type="text" name="table"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

<?php

$con = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("db",$con) or die(mysql_error());

$tname = $_POST[table];


// Creating a table with an attributes: ID and name
$data = "Create table ". $tname . "(ID int, name varchar(30))";
$query = mysql_query($data);

if($query)
echo "New table is created";
mysql_close($con);

?>

heavensgate15
07-01-2009, 12:51 PM
you can try this website: www.w3schools.com