mickey -
Joined: 09 Dec 2002 Posts: 25
|
Posted: Mon Feb 17, 2003 2:21 pm Post subject: Script problems, Help please! |
|
|
:? Can anyone please help me with this script problem:
I keep getting the following message:
Quote: |
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 '(),date_acq date ())' at line 1 |
this is the page that generates it, I had a look at the manual that they refer to and the code that I'm using looks fine, can someone please take a look and tell me if I'm going wrong somewhere.
Code: | <?
//indicate the database you want to use
$db_name = "testDB";
//connect to database
$connection = @mysql_connect("localhost", "minx", "3jh5Gl7") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
//start creating the SQL statement
$sql = "CREATE TABLE $_POST[table_name] (";
//continue the SQL statement for each new field
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 .= ",";
}
}
//clean up the end of the string
$sql = substr($sql, 0, -1);
$sql .= ")";
//execute the query
$result = mysql_query($sql, $connection) or die(mysql_error());
//get a good message for display upon success
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>
|
don't know if you need this, this is the code for the page before the one above:
Code: |
<form method="post" action="do_createtable.php">
<input type="hidden" name="table_name" value="my_music">
<table cellspacing=5 cellpadding=5>
<tr>
<th>Field Name</th><th>Field Type</th><th>Field Length</th></tr>
<tr>
<td align=center><input type="text" name="field_name[]" size="30"><td>
<td align=center>
<select name="field_type[]">
<option value="char">char</option>
<option value="date">date</option>
<option value="float">float</option>
<option value="int">int</option>
<option value="text">text</option>
<option value="varchar">varchar</option>
</select>
</td>
<td align=center><input type="text" name="field_length[]" size="5"></td>
</tr>
|
Thanks |
|