I can't figure what what is wrong with this code. The problem lyes in the VALUES line, which I can't seem to get coded to collect form data. This php file is posted in my HTML form with the text fields "firstname" "surname" and "location"..
<?
$location = "localhost";
$username = "myusername";
$password = "mypass";
$database = "mydatabase";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not open MySQL connection!");
mysql_select_db($database,$conn) or die ("Could not open database!");
mysql_query("CREATE TABLE users (
firstname VARCHAR(20),
surname VARCHAR(20),
location VARCHAR(20))");
$insert = "INSERT INTO users (firstname,surname,location)
VALUES ($_POST['firstname'],$_POST['surname'],$_POST['location']);
mysql_query($insert) or die ("Could not add any data to specified table");
$query = "SELECT * FROM users";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
echo "You have $numrows rows in the database<br>";
echo "First Name: $row[firstname]<br>";
echo "Surname: $row[surname]<br>";
echo "Location: $row[location]<br><br>";
}
?>
Error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/user12/public_html/development/test/testthis.php on line 18