Reputation: 33
I'm having problems with this php code which needs to create a table in the database specified by the user. But whenever I try to execute the SQL it tells me no database selected. My code is as follow
<?php
$con = mysql_connect("127.0.0.1","peter")
or die('Error connecting to mysql'); // Check connection
// Create table
mysql_select_db("USE Ebooks");//Select Database
$foldername = mysql_real_escape_string($_POST['foldername']);//Obtain Folder Name
$sql = sprintf("CREATE TABLE %s (ID CHAR(3) ,Books CHAR(30))", $foldername);
mysql_query($sql) or die(mysql_error());
mysql_close($con);
?>
Upvotes: 3
Views: 9945
Reputation: 20209
Use
mysql_select_db( "Ebooks" ) or die( 'Error'. mysql_error() );
Upvotes: 3