Jump to content

Recommended Posts

Well Look at the script first

<?php
include 'config.php';
include 'opendb.php';
$dbtoadd = $_GET["user"];

$query  = 'CREATE DATABASE phpcake';
$result = mysql_query($query);

mysql_select_db('swd-dbweb') or die('Cannot select database');

$query = 'CREATE TABLE $dbtoadd( '.
         'cid INT NOT NULL AUTO_INCREMENT, '.
         'cname VARCHAR(20) NOT NULL, '.
         'cemail VARCHAR(50) NOT NULL, '.
         'csubject VARCHAR(30) NOT NULL, '.
         'cmessage TEXT NOT NULL, '.
         'PRIMARY KEY(cid))';

$result = mysql_query($query);

include 'closedb.php';
?>

You wont need Config.php or opendb.php cause thats just connection but as you can see to make the Table you will have to type script.php?user=tablename but when it makes it it just makes a database with $dbtoadd there must be a trick to making this work

Please and thanks :)

Link to comment
https://forums.phpfreaks.com/topic/89667-solved-creating-mysql-tables-problem/
Share on other sites

In the following code, you need to use double quotes for php to parse the variables inside the quotes.

 

$query = 'CREATE TABLE $dbtoadd( '.
         'cid INT NOT NULL AUTO_INCREMENT, '.
         'cname VARCHAR(20) NOT NULL, '.
         'cemail VARCHAR(50) NOT NULL, '.
         'csubject VARCHAR(30) NOT NULL, '.
         'cmessage TEXT NOT NULL, '.
         'PRIMARY KEY(cid))';

 

edit: technically you could just do

 

$query= 'CREATE TABLE '.$dbtoadd.'('.

the rest is fine

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.