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 .= ")";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.