Page 1 of 1

Using a For loop to create a table

Posted: Sat Oct 02, 2004 10:17 pm
by wadesmart
feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


10022004 2213 GMT-6

Im learning PHP from an older book so Im taking the code and trying to figure out how to use it with the new globles variable off. 

This bit of code Im having trouble with.

Code: Select all

$sql = "CREATE TABLE  $t_name (";
		for ($i = 0; $i < count($f_name); $i++) {
			$sql .= "$f_name[$i] $f_type[$i]";

				if ($f_length[$i] !="") {
					$sql .= " ($f_length[$i] ), ";
				}	else	{
				$sql .= ", ";
			}
		}
	$sql .= ")";

What is happening is, a page takes a desired table name and the number of fields and hands it to the next page. This second page creates the number of desired fields and then you select the name of the fields aong with the field type. The final page takes the information and puts it in to a database.

This piece of code is supposed to create the table with the correct amount of fields and field types.

I receive this error upon exceution:

Code: Select all

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 '&#1111;\\''table_name\\''] (A A (A ), )' at line 1
Any help is greatly appreciated.

Wade


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Oct 02, 2004 10:21 pm
by feyd
post an echo of the $sql variable just before you send it to mysql.