Hi all I'm trying to learn php by myself I got as far as creating my first data base and table using the following code:
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not conect: '.mysql_error());
}
//Create database
if (mysql_query("CREATE DATABASE FATBYTES",$con))
{
echo "Database created";
}
else
{
echo "Error creating database ;".mysql_error();
}
//CREATE TABLE
mysql_select_db("FATBYTES",$con);
$sql = "CREATE TABLE Customers
(
MobileNumber varchar(10),
Sex varchar(8),
FirstName varchar(15),
LastName varchar(15),
Age int,
Email varchar(30)
)";
//Execute Query
mysql_query($sql,$con);
mysql_close($con);
The above works as I can access the database and table through phpMyadmin however the following insert does not work.I get this error"You have a mySQL syntax error...and so on"
$cellno="TEST";
$Title="TEST";
$FirstName="TEST";
$SurName="TEST";
$Age="12";
$Email="TEST";
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not conect: '.mysql_error());
}
//CREATE TABLE
mysql_select_db("FATBYTES",$con);
//Execute Query
$query = "INSERT INTO Customers (MobileNumber,Sex,FirstName,LastName,Age,Email) VALUES ('$cellno','$Title'','$FirstName','$SurName',8,'$Email')";
if(!(mysql_query($query,$con)))
{print("Couldn't make it happen<br/>");
die(mysql_error());}
mysql_close($con);
Any help highly appreciated.