I'm a bit new to PHP and everything was going super smooth until this:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'C)' at line 1"
I've looked over my code over and over again but I can't seem to understand why its not working.
Code:
<?
$db_name = "ijdb";
$connection = @mysql_connect("localhost", "root", "1234") 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 = "<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>
So please if you can help me understand what I'm doing wrong I'd greatly appreciate it.
I hope it's not something stupid like a misplaced quotation mark, but then again I don't
think that would be far off from everyones' first post. Anyway HELP!

New Topic/Question
Reply




MultiQuote




|