Hi I am doing this HTML.net tutorial on php.I keep getting this error and I cannot figure out how to fix it.I am running php version 5.4 maybe this is the problem, I appreciate tour help:
Parse error: syntax error, unexpected 'TABLE' (T_STRING) in C:\inetpub\wwwroot\phpconnect.php on line 6
This is the code:

mysql_connect("localhost", "root", "LaTorre1937##") or die(mysql_error());
    mysql_select_db("mydatabase") or die(mysql_error());

    CREATE TABLE people (
    FirstName CHAR, 
    LastName CHAR,
    Phone INT,
    BirthDate DATE,


The create table needs to be in a string, to be executed by the mysql_query function. It's an SQL script, not PHP code.

Hi, I am sorry I posted the wrong code.This happened because I am doing 3 different tutorials at the same time so I guess I got confused, I know the difference between sql language and php.The code below is the one I wanted to ask for some help, I keep getting this errors:
Notice: Undefined index: firstname in C:\inetpub\wwwroot\datain.php on line 14

Notice: Undefined index: lastname in C:\inetpub\wwwroot\datain.php on line 15

Notice: Undefined variable: name in C:\inetpub\wwwroot\datain.php on line 21
Thanks for your help

<form method="post" action="datain.php">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Nick Name:<input type="Text" name="nickname"><br>
E-mail:<input type="Text" name="email"><br>
Salary:<input type="Text" name="salary"><br>
<input type="Submit" name="submit" value="Enter info">


 $host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="LaTorre1937##"; // Mysql password 
$db_name="learndb"; // Database name 
$tbl_name="personnel"; // Table name 

// Connect to server and select database.
 mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form 

 // Insert data into mysql 
 $sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";

// if successfully insert data into database, displays message "Successful". 
 echo "Successful";
 echo "<BR>";
 echo "<a href='insert.php'>Back to main page</a>";

 else {
 echo "ERROR";

// close connection 

your $_POST variables don't exist until after you submit your form

You can use isset($_POST['submit']) to check if your form has been submited

also take a look at mysql_real_escape_string

commented: agreed +14

Hi thanks for your help.I am not sure though where to insert that isset code.If I am not asking too much as I am a beginner could you please amend that code for me so I can figure it out? If not thanks a lot anyway I'll keep studying and trying.

if (isset($_POST['submit']))
    // form submited so prosses the results
    // and put them into the db
    // tell the user succes or fail 
    // form not submited so lets display it
    <form ...

It won't work, because you have errors.

First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>

is in your form markup but,

// Get values from form 

is what your code is looking for. The 'name' attribute in the form must match the 'S_POST' request.