don't you just love query errors?
I get this Mysql Error:
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 'address_two varchar ,address_three varchar ,postcode varchar ,country varchar ,p' at line 1
I am submitting results of a form that creates a table to this script:
<?php
$db_name = "markbad_markbadsql";
$connection=mysql_connect ("localhost", "markbad_drpl1", "removed")
or die ('I cannot connect to the database because: ' . mysql_error());
$db = mysql_select_db ($db_name, $connection)
or die ('I cannot connect to the database because: ' . mysql_error());
//start creating SQL statment
$sql = "CREATE TABLE $_POST[table_name] (";
//continue SQL statement for each 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 Query
$result = mysql_query($sql,$connection)
or die (mysql_error());
// Get a good result if sucessful
if ($result) {
$msg = "<p>".$_POST[table_name]." has been created!</p>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link href="http://www.eriescene.com/layout.css" rel="stylesheet" type="text/css" />
<title>Show Fields Script</title>
<link href="layout.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="title">
</div>
<div id="frame1">
<img src="http://www.eriescene.com/images/SideMenu1.gif" alt="Erie Scene Menu" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="20,17,171,46" href="index.htm" alt="Home Of Erie Bars" />
<area shape="rect" coords="19,53,172,80" href="erie-bar-club-event/erie-bars.php" alt="Erie Bars Directory" />
<area shape="rect" coords="18,87,171,112" href="contact-us.php" alt="Contact The Erie Scene" />
<area shape="rect" coords="19,118,173,145" href="erie-open-chat/index.php" target="_blank" alt="Erie Chat Rooms" />
<area shape="rect" coords="21,151,173,178" href="erie-forums/index.php" alt="Erie Forum" />
<area shape="rect" coords="20,184,173,212" href="erie-pa-events/index.html" alt="Erie Events" />
<area shape="rect" coords="20,218,172,244" href="free-erie-media.htm" />
<area shape="rect" coords="19,249,172,280" href="erie/index.htm" alt="Erie Pa Sports Schedule" />
</map>
</div>
<div id="frame2">
</div>
<div id="frame3">
</div>
<div id="frame4">
<table class="align" width="85%">
<tr>
<td height="326">
<h1>adding to table <? echo "$result"; ?>...</h1>
<? echo "$msg"; ?>
<a href="users.php">Go Back To Users</a>
</td>
</tr>
</table>
<!-- rest of html -->
What am I doing wrong this time? I am pretty sure this script worked before. I just had never input a type "varchar" yet until today and this is the error I got.