Help with Parse Error:
Posted: Thu Apr 01, 2004 11:59 am
Here is the error im getting :
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 10
Here is my code:
Line 10 is :
Any ideas?
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 10
Here is my code:
Code: Select all
<?
//indicate the database you want to use
$db_name ="Inventory";
//connect to database
$connection = @mysql_connect("localhost","byron","byronb") or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());
//start creating the SQL statement
$sql = "CREATE TABLE $_POST['table_name'] (";
//continue the SQL statement for each new field
for ($i =0; $i < count($_POST['field_name']); $i++) {
$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
if ($_POST[auto_increment][$i] == "Y") {
$additional ="NOT NULL auto_increment";
} else {
$additional ="";
}
if ($_POST[primary][$i] == "Y") {
$additional .=", primary key (".$_POST[field_name][$i].")";
} else {
$additional ="";
}
if ($_POST[field_length][$i] != "") {
$sql .="(".$_POST[field_length][$i].")$additional ,";
} else {
$sql .="$additional ,";
}
}
//clean up the end of the string
$sql = substr($sql,0,-1);
$sql .= ")";
//execute the query
$result = mysql_query($sql,$connection) or die(mysql_error());
//get a good message for display upon success
if ($result) {
$msg ="<P>".$_POST [table_name]."has been created!</P>";
}
?>
<HTML>
<HEAD>
<TITLE>Create a Database Table:Step 3</TITLE>
</HEAD>
<BODY>
<h1>Adding table to <? echo "$db_name"; ?>...</h1>
<? echo "$msg"; ?>
</BODY>
</HTML>Code: Select all
$sql = "CREATE TABLE $_POST['table_name'] (";