| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |
|

12-10-02, 14:41
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
syntax errors...
|

12-10-02, 17:15
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 11
|
|
well can't see the rest of the page, your error seems to be in the query but you cut it off. just post the create table code so we can help you.
|
|

12-10-02, 18:08
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
|
Ah sorry, thought the error was in the top 2 lines! Anyway...
Code:
<?php
// db connection //
$connection = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("nameofdb") or die(mysql_error());
// db querys //
$sql = "CREATE TABLE $_POST[table_name] (";
// loop start //
for ($i = 0; $i < count($_POST[fieldname]); $i++) {
// field name query //
$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
// field definintions //
if ($_POST[field_length][$i] != "") {
$sql .= " (".$_POST[field_length][$i]."),";
// crappy other block thing //
} else {
$sql .= ",";
}
// close loop //
}
// some crappy func //
$sql = substr($sql, 0, -1);
// close parent //
$sql .= ")";
// db query shit //
$result = mysql_query($sql,$connection) or die(mysql_error());
// testing values //
if ($result) {
$msg = "<p>".$_POST[table_name]." has been created!</p>";
}
?>
<HTML>
<HEAD>
<TITLE>Create a Database Table: Step 3</TITLE>
</HEAD>
<BODY>
## nice info ##
<h1>Adding table to database...</h1>
// print message //
<?php echo "$msg"; ?>
// validate //
</BODY>
</HTML>
|
|

12-10-02, 18:17
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 11
|
|
you forgot your ending ) in this line
PHP Code:
if ($_POST[field_length][$i] != "") {
$sql .= " (".$_POST[field_length][$i].")")";
// crappy other block thing //
} else {
$sql .= ",";
}
also you can't have a , at the end...
|
|

12-11-02, 09:48
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
I get a parse error on line 45..
|
|

12-11-02, 10:08
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 11
|
|
oh sorry I forgot a " in there, try this and tell us what it echos out?
PHP Code:
<?php
// db connection //
$connection = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("nameofdb") or die(mysql_error());
// db querys //
$sql = "CREATE TABLE $_POST[table_name] (";
// loop start //
for ($i = 0; $i < count($_POST[fieldname]); $i++) {
// field name query //
$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
// field definintions //
if ($_POST[field_length][$i] != "") {
$sql .= " (".$_POST[field_length][$i]."),";
// crappy other block thing //
} else {
$sql .= ",";
}
// close loop //
}
// some crappy func //
$sql = substr($sql, 0, -1);
// close parent //
$sql .= ")";
// db query **** //
echo $sql;
$result = mysql_query($sql,$connection) or die(mysql_error());
if (!$result){echo mysql_error();}
// testing values //
if ($result) {
$msg = "<p>".$_POST[table_name]." has been created!</p>";
}
?>
<HTML>
<HEAD>
<TITLE>Create a Database Table: Step 3</TITLE>
</HEAD>
<BODY>
## nice info ##
<h1>Adding table to database...</h1>
// print message //
<?php echo "$msg"; ?>
// validate //
</BODY>
</HTML>
|
|

12-11-02, 12:03
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
CREATE TABLE )You have an error in your SQL syntax near ')' at line 1
|
|

12-11-02, 15:46
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 11
|
|
what does your form look like?
|
Last edited by scoutt : 12-11-02 at 16:26.
|

12-11-02, 16:33
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 11
|
|
I noticed that you have different names for the fieldname
$_POST[fieldname] and
$_POST[field_name]
make sure you get the right one.
|
|

12-12-02, 07:23
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
Corrected the error, but I still get the same syntax error as before. :/
|
|

12-12-02, 09:44
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 11
|
|
and I still want to know what your form looks like. is field_name an array?
|
|

12-12-02, 11:55
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
PHP Code:
<?
// checker //
if ((!$_POST[table_name]) || (!$_POST[num_fields])) {
echo "You will need to enter values for <b>each</b> field.";
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 ALUGN=CENTER COLSPAN=3><INPUT TYPE=\"submit\" VALUE=\"Create Table\"></TR></TD></TABLE></FORM>";
?>
<HTML>
<HEAD>
<TITLE>
Create a Database Table: Step 2</title>
</HEAD>
<BODY>
<h1>Define fields for <? echo "$_POST[table_name]"; ?></h1>
<!-- display form block -->
<? echo "$form_block"; ?>
<!-- validate -->
</BODY>
</HTML>
Thats the form that links to the create table file. This file is linked with a previous form to find out the table name and number of fields.
|
|

12-12-02, 14:47
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 11
|
|
well, I changed this
for ($i = 0; $i < count($_POST[fieldname]); $i++) {
to this
for ($i = 0; $i < count($_POST[field_name]); $i++) {
and it worked fine.
|
|

12-12-02, 17:25
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
I fixed mine with what you did but I still get the same syntax error.
Maybe the database is corrupted? Version of PHP? What things would cause this?
|
|

12-12-02, 17:28
|
|
Registered User
|
|
Join Date: Dec 2002
Posts: 17
|
|
Just tested it, it worked!
Thankyou so much for your help! *is very happy now  *
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|