Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 16th, 2004, 02:18 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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!



Reply With Quote
  #2  
Old January 16th, 2004, 02:48 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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.

Reply With Quote
  #3  
Old January 16th, 2004, 02:59 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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>


Reply With Quote
  #4  
Old January 16th, 2004, 03:05 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: Wrong Syntax?!

php Code:
Original - php Code
  1.  
  2. <?
  3. $sql = "CREATE TABLE ".$_POST['table_name']." (";
  4. for ($i = 0; $i < count($_POST['field_name']); $i++) {
  5. $sql .= $_POST['field_name'][$i]." ".$_POST['field_type'][$i];
  6. if ($_POST['field_length'][$i]) {
  7. $sql .= " (".$_POST['field_length'][$i])."), ";
  8. } else {
  9. $sql .= ", ";
  10. $sql = substr($sql, 0, -1);
  11. $sql .= ");";
  12. ?>

Reply With Quote
  #5  
Old January 16th, 2004, 03:31 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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>


Reply With Quote
  #6  
Old January 16th, 2004, 03:43 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: Wrong Syntax?!

Modified your code... check whether this works!
php Code:
Original - php Code
  1.  
  2. <?
  3. // create connection; substitute your own information
  4. $conn = mysql_connect("localhost","luis","elpingo") or die(mysql_error());
  5.  
  6. // select database; substitute your own database name
  7. mysql_select_db("dbtest", $conn) or die(mysql_error());
  8.  
  9. $table_name=$_POST['table_name'];
  10. $field_name=$_POST['field_name'];
  11. $field_type=$_POST['field_type'];
  12. $field_length=$_POST['field_length'];
  13. ?>
  14. <HTML>
  15. <HEAD>
  16. <TITLE>Create a Database Table: Step 3</TITLE></HEAD>
  17. <BODY>
  18. <h1>Adding table <? echo $table_name; ?></h1>
  19. <?
  20. $sql = "CREATE TABLE $table_name (";
  21. for($i=0;$i<count($field_name);$i++)
  22. {
  23.     $sql.= $field_name[$i]." ".$field_type[$i];
  24.     if($field_length[$i]!="") $sql.= " (".$field_length[$i]."),";
  25.     else $sql.=",";
  26. }
  27. $sql = substr($sql,0,-1);
  28. $sql.= ")";
  29.  
  30. // execute SQL query and get result
  31. $sql_result = mysql_query($sql) or die(mysql_error());
  32.  
  33. //print success message
  34. if ($sql_result) {
  35. echo "<P>$table_name has been created!</p>";
  36. }
  37. ?>
  38. </BODY>
  39. </HTML>
  40.  

Reply With Quote
  #7  
Old January 16th, 2004, 04:05 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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!

Reply With Quote
  #8  
Old January 16th, 2004, 04:10 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
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!!

Reply With Quote
  #9  
Old January 16th, 2004, 04:14 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Wrong Syntax?!

you're right hehe

Thanks for your help!!

Reply With Quote
  #10  
Old March 24th, 2004, 11:30 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Wrong Syntax?!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |