I am only starting with php and mysql I have been doing VB which is very simple and now i struggle with every bit of php. I made small piece of code which conncects to mysql server as a root and creates a database with the name entered in the text field but whenever I load the page I see a error message before I even get chance to type db name and to hit the button.
The code does the job but gives a confusing error message.
Notice: Undefined index: dbname in C:\xampp\htdocs\dbcreation.php on line 53
Error creating database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line
<?php
$databasename = $_POST['dbname'];
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE $databasename",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
what do I need to change so code is not executed untill i press the button?
Check to see if the variable exists.