Hi,
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:
<?php
//connect to the server
$con=mysql_connect(“servername”,“username”,“password”);
if(!$con){
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),
PRIMARY KEY (ID),
UNIQUE id (ID)
)”;
mysql_query($sql,$con);
mysql_close($con);
?>