Jump to content

Creating Form in PHP to insert table in mySQL db


buchberg

Recommended Posts

Need a little help with this code.  I'm running Apache 2.21 / PHP 5.3.5 on Windows.  This is a V6 application.  I am running Windows 7.  I am new, and trying to learn.  What am I doing wrong in line 8 with the 'if' statement?  The idea is to create a table in mySQL using a form interface.   

 

Thank you in advance.

 

Parse error: syntax error, unexpected '{' in C:\website\do_createtable.php on line 8

<?

$db_name="booster";

$connection=mysql("localhost", "user", "password") or die (mysql_error());

$db=mysql_select_db($db_name, $connection) or die (mysql_error());

$sql="CREATE TABLE $_POST[table_name] (";

for ($i=0; $i < count($_POST[field_name]); $i++) {

$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];

if ($_POST[field_length][$i] != "" {

$sql .= " (".$_POST[field_length][$i]."),";

} else {

$sql .= ",";

}

}

$sql=substr($sql,0,-1);

$sql .= ")";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.