Jump to content

[SOLVED] Creating MYSQL tables Problem


winmastergames

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

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.