Basic Php / SQL problem


This is my first post and I’m really hoping someone can help me on this since I’ve been pulling my hair out for a few days. I’m new to writing Php code and have been trying to write a program that will create an SQL database then create a table within that database, but when I run the program the database is created but there is no table. I would be grateful if somebody could give me some pointers where I could be going wrong. I included my code below:

//connect to the server
die('Could not connect to SQL: '. mysql_error());

//create a new database stock data
if(mysql_query(“CREATE DATABASE Stock_data”, $con)){
print “Database Created”;
} else {
print"Error Creating database: " . mysql_error();
// link to database stock_data
mysql_select_db(“Stock_data”, $con);
//create table
$sql=“CREATE TABLE med_record
ID int(7) NOT NULL auto_increment,
Name varchar(50) NOT NULL,
Quantiy varchar(50) NOT NULL,
Date of expiry varchar(50),


you need database name in connection

you have a syntax error in your sql query to create the table.

if you run your query in something like phpMyadmin first your error should become clear.

when I correct the error, your database and table are created without any problems.

Sorry guys been away for a Christmas break; hope yours has gone well.

I have done as you have suggested and have fixed the problem, thanks for all your help.