|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Wrong Syntax?!
I'm using a G5 10.2.8
SQL version is 4.0.17 I'm getting this error and I AM positive that my syntax must be right! Adding table my_table 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 '[0] Array[0] (Array[0]), Array[1] Array[1] (Array[1]), Array[2] I checked the MySQL manual but couldn't find it... This is the code used... [highlight=php] <? if ((!$_POST[table_name]) || (!$_POST[num_fields])) { header( "Location: http://127.0.0.1/show_createtable.html"); exit; } $form_block = " <FORM METHOD="POST" ACTION="do_createtable.php"> <INPUT TYPE="hidden" NAME="table_name" VALUE="$_POST[table_name]"> <TABLE CELLSPACING=5 CELLPADDING=5> <TR> <TH>FIELD NAME</TH><TH>FIELD TYPE</TH><TH>FIELD LENGTH</TH></TR>"; for ($i = 0; $i < $_POST[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:</TITLE> </HEAD> <BODY> <H1>Define fields for <? echo "$_POST[table_name]"; ?></H1> <? echo "$form_block"; ?> </BODY> </HTML> [highlight=php] Thank you! |
|
#2
|
|||
|
|||
|
RE: Wrong Syntax?!
I do not see where this query is being executed in the code you posted, please post the code that builds and executes the query. That is where the problem is.
|
|
#3
|
|||
|
|||
|
Ups!
<HTML>
<HEAD> <TITLE>Create a Database Table: Step 3</TITLE></HEAD> <BODY> <h1>Adding table <?php echo "$_POST[table_name]"; ?></h1> <?php $sql = "CREATE TABLE $_POST[table_name] ("; 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); $sql .= ")"; // create connection; substitute your own information $conn = mysql_connect("localhost","luis","mypass") or die(mysql_error()); // select database; substitute your own database name $db = mysql_select_db("dbtest", $conn) or die(mysql_error()); // execute SQL query and get result $sql_result = mysql_query($sql,$conn) or die(mysql_error()); //print success message if ($sql_result) { echo "<P>$_POST[table_name] has been created!</p>"; } ?> </BODY> </HTML> |
|
#4
|
|||
|
|||
|
RE: Wrong Syntax?!
|
|
#5
|
|||
|
|||
|
Wrong Syntax again
Thanks for your input but now I get...
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /Library/WebServer/Documents/do_createtable.php on line 5 here's the complete code <HTML> <HEAD> <TITLE>Create a Database Table: Step 3</TITLE></HEAD> <BODY> <h1>Adding table <?php echo "$_POST['table_name']"; ?></h1> <? $sql = "CREATE TABLE ".$_POST['table_name']." ("; 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); $sql .= ");"; ?> // create connection; substitute your own information $conn = mysql_connect("localhost","luis","elpingo") or die(mysql_error()); // select database; substitute your own database name $db = mysql_select_db("dbtest", $conn) or die(mysql_error()); // execute SQL query and get result $sql_result = mysql_query($sql,$conn) or die(mysql_error()); //print success message if ($sql_result) { echo "<P>$_POST[table_name] has been created!</p>"; } ?> </BODY> </HTML> |
|
#6
|
|||||
|
|||||
|
RE: Wrong Syntax?!
Modified your code... check whether this works!
php Code:
|
|
#7
|
|||
|
|||
|
RE: Wrong Syntax?!
Parse error: parse error in /Library/WebServer/Documents/do_createtable.php on line 7
Something is wrong, let me see if I can figure it out ! Thanks a lot! |
|
#8
|
|||
|
|||
|
RE: Wrong Syntax?!
It should be something else causing the parse error then, not the above posted code. Surely, it worked for me here in my server.
I think you reffer to "PHP fast & easy web development" book by Julie C. Meloni!! |
|
#9
|
|||
|
|||
|
RE: Wrong Syntax?!
you're right hehe
Thanks for your help!! |
|
#10
|
|||
|
|||
|
RE: Wrong Syntax?!
nice work. I had the wrong sytax array[o] et etc error message, and being a complete newbie at php was tearing my hair out.
With a small snippet of your code ere I was able to create the table and finally go get myself a coffee. I'll be coming back when I hit the next wall, sorry IF I hit a wall (touch wood!) Thanks again! |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Wrong Syntax?! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|