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);
?>
Use
mysql_select_db( "Ebooks" ) or die( 'Error'. mysql_error() );
Use this code:
mysql_select_db("Ebooks");//Select Database
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With