I have 3 files
1) show_createtable.html
2) do_showfielddef.php
3) do_showtble.php
1) First file is for creating a new table for a data base, it is a fom with 2 inputs, Table Name and Number of Fields. THIS WORKS FINE!
Untitled Document
Step 1: Name and Number
Table Name:
Number of fields:
2) this script validates fields and createa another form to enter all the table rows.
This for also WORKS FINE!
//validate important input
if ((!$_POST[table_name]) || (!$_POST[num_fields])) {
header( "location: show_createtable.html");
exit;
}
//begin creating form for display
$form_block = "
";
?>
Create a database table: Step 2
defnie fields for
Problem is here
3) this form creates the tables and enteres them into the database.
I am getting an error on line 37 "Parse error: syntax error, unexpected $end in /home/admin/domains/domaina.com.au/public_html/do_createtable.php on line 37"
$db_name = "testDB";
$connection = @mysql_connect("localhost", "admin_user", "pass")
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 .= ")";
$result = mysql_query($sql, $connection) or die(mysql_error());
if ($result) {
$msg = "" .$_POST[table_name]." has been created!
";
?>
Create A Database Table: Step 3
Adding table to ...
Answer
$result = mysql_query($sql, $connection) or die(mysql_error());
if ($result) {
$msg = "" .$_POST[table_name]." has been created!
";
}
you missing a }
in your last if statement, and your for loop is missing a }
too
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 .=",";
}
}
No comments:
Post a Comment