I am trying to create a two step form sequence using three files - one file is html and the other two are php.
I am using Julie Meloni's book, "PHP Fast and Easy" as my source and the code is from that book on pp.198-209. The three files are: 1. show_createtable.html 2. do_showfielddef.php 3. do_createtable.php I am able to connect to mysql since I have tested her previous scripts before this chapter. And, I am able to fill out and submit the first html form which is merely two textboxes with a place for your table name and number of fields. I then submit that form and get the second script (do_showfielddef.php) where I have three boxes for the attributes of the fields - name, type and length. When I fill out that form and hit submit... I am getting a: "Couldn't execute query" . This happens on many of my tables that I am trying to create. I have listed the three scripts below. If anybody can assist me that would be great. Please note that her username and password in the mysql_connect function are taken from the book. Many thanks, Tony Ritter ....................................................... // #1 script <HTML> <HEAD> <TITLE>Create a Database Table: Step 1</TITLE> </HEAD> <BODY> <H1>Step 1: Name and Number</H1> <FORM METHOD="POST" ACTION="do_showfielddef.php"> <P><strong>Table Name:</strong><br> <INPUT TYPE="text" NAME="table_name" SIZE=30></p> <P><strong>Number of Fields:</strong><br> <INPUT TYPE="text" NAME="num_fields" SIZE=5></p> <P><INPUT TYPE="submit" NAME="submit" VALUE="Go to Step 2"></p> </FORM> </BODY> </HTML> ......................................................... // #2 script <? if ((!$table_name) || (!$num_fields)) { header( "Location: http://localhost/show_createtable.html"); exit; } $form_block = " <FORM METHOD=\"POST\" ACTION=\"do_createtable.php\"> <INPUT TYPE=\"hidden\" NAME=\"table_name\" VALUE=\"$table_name\"> <TABLE CELLSPACING=5 CELLPADDING=5> <TR> <TH>FIELD NAME</TH><TH>FIELD TYPE</TH><TH>FIELD LENGTH</TH></TR> "; // create form fields on the fly for ($i = 0 ; $i <$num_fields; $i++) { $form_block .= " <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> "; } $form_block .= " <TR> <TD ALIGN=CENTER COLSPAN=3><INPUT TYPE=\"submit\" VALUE=\"Create Table\"></TD> </TR> </TABLE> </FORM> "; ?> <HTML> <HEAD> <TITLE>Create a Database Table: Step 2</TITLE> </HEAD> <BODY> <H1>Define fields for <? echo "$table_name"; ?></H1> <? echo "$form_block"; ?> </BODY> </HTML> ........................................................... // # 3 script <? $db_name = "testDB"; $connection = @mysql_connect("localhost", "sandman", "tQ9472b") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "CREATE TABLE $table_name ("; for ($i = 0; $i < count($field_name); $i++) { $sql .= "$field_name[$i] $field_type[$i]"; if ($field_length[$i] != "") { $sql .= " ($field_length[$i]),"; } else { $sql .= ","; } } $sql = substr($sql, 0, -1); $sql .= ")"; $result = mysql_query($sql,$connection) or die("Couldn't execute query."); if ($result) $msg = "<P>$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> -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]