This question already has an answer here:
<?php
include('database_connection.php');
$email = $_SESSION['Email'];
$q = 'SELECT *
FROM `'.$email.'`
LIMIT 0 , 30';
$r = mysqli_query ($dbc, $q);
if( $r )
{
echo '<table class="responsive">';
echo '<tr><td><strong>Name</strong></td><td><strong>Description</strong></td><td><strong>Date</strong></td><td><strong>Shared?</strong></rd><td><strong>Edit:</strong></td><td><strong>View:</strong></td></tr>';
while($row = mysqli_fetch_array($r, MYSQLI_BOTH)) {
echo'<tr><td>'.$row[6].'</td><td>'.$row[7].'</td><td>'.$row[8].'</td><td>'.$row[2].'</td><td><a href="https://daccaa.com/beta/edits/editor.php?file='.$row[5].'" class="select">Edit</a></td><td><a href="https://daccaa.com/beta/edits/view.php?file='.$row[5].'" class="select">View</a></td></tr>';
}
mysqli_free_result($r);
echo "</table>";
} else {
$mysqlcode = "CREATE TABLE `".$email."` (
`id` INT( 8 ) NOT NULL ,
`Note` text NOT NULL ,
`Share` VARCHAR( 200 ) DEFAULT 'No' NOT NULL ,
`Share Url` VARCHAR( 200 ) NOT NULL ,
`Short Url` VARCHAR( 200 ) NOT NULL ,
`Location` VARCHAR( 200 ) NOT NULL ,
`Name` VARCHAR( 200 ) NOT NULL ,
`Description` VARCHAR( 200 ) NOT NULL ,
`Date` VARCHAR( 40 ) NOT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;";
$d = mysql_query($dbc, $mysqlcode);
if($d) {
echo 'Created Database For your notes.';
$sql = 'INSERT INTO `example` (`id`, `Note`, `Share`, `Share Url`, `Short Url`, `location`, `Name`, `Description`, `Date`) VALUES (\'0\', \'Welcome to Daccaa Edits, here you can make and edit notes and pictures.\', \'No\', \'\', \'\', \'welcome.txt\', \'Welcome\', \'This is a welcome note.\', \'07/06/2014\')';
$i = mysql_query($dbc, $sql);
if($i) {
echo '<h2>Created a first note.</h2>';
} else {
echo '<h2>Failed to create a note for you.</h2>';
}
} else {
echo 'Failed to create database for you notes.';
}
}
mysqli_close($dbc);
?>
This is my code, I am trying to make it so if the Table in a database does not exist then it will create a Table for a certain database with the table name being the Users Email. I have tested the MYSQL code directly in PHPmyadmin and it seems to work. I have come to the point now where I am unsure what is wrong.
The first bit works where it displays the information from the database and table when I have already manually created the database.
I will be adding more security prevention methods along the way but if anyone does have any suggestions I will try and implement them.
All ideas help.