Thanks to Jay B, the puzzle is no more. Turns out assigning a field length to the text field type caused the problem. I left out the field length for this data type and the script now works.

He also offered a helpful explanation about this data type:
http://dev.mysql.com/doc/mysql/en/BLOB.html

"In most respects, you can regard a TEXT column as a VARCHAR column that
can be as big as you like. "

"The maximum size of a BLOB or TEXT object is determined by its type,
but the largest value you actually can transmit between the client and
server is determined by the amount of available memory and the size of
the communications buffers. "

Thanks, Jay.
Amy

On Sep 30, 2004, at 12:01 PM, Amy Rogers wrote:

I need help understand the error following message I got. The related script is below. I also have a separate question about dots that appear in the script. I am using Julie Meloni's PHP Essentials 2nd Edition to learn the language, and this is taken from page 119.

(I was trying to create a new table with 4 fields to store userids and passwords. I used the same script successfully to create a different table and am confused why it is not working this time.)

Error message:
"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 '(20),username text (10),password varchar (10))' at line 1"


A separate question:
What is the meaning of the "." on each end of the ".$_POST[field_length][$i]." ?


Here's the relevant part of the script:

<?php
$sql = "create table $_POST[table_name] (";
//to create the fields you specified in Step 2
//create loop to populate the remainer of the sql statement
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);
//close the SQL statement
$sql .= ")";
$conn = mysql_connect("localhost", "userid", "password") or die(mysql_error());
$db = mysql_select_db ("aroDB", $conn) or die(mysql_error());
$sql_result = mysql_query($sql, $conn) or die(mysql_error());
if ($sql_result) {
echo "<p>$_POST[table_name] has been created.</p>";
}
?>



-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to