Re: New to PHP, and stuck
| From: | 1LT John W. Holmes | Date: | Wed, 06 Nov 2002 13:59:06 +0000 |
| Subject: | Re: New to PHP, and stuck | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123002@lists.php.net to get a copy of this message | ||
Also, you should echo out $sql so you can see what is actually created. It
will probably be obvious what the error is.
---John Holmes...
----- Original Message -----
From: "Edward Peloke" <epeloke@echoman.com>
To: "Markus Jäntti" <janmark@bodo.kommune.no>; <php-general@lists.php.net>
Sent: Wednesday, November 06, 2002 9:19 AM
Subject: RE: [PHP] New to PHP, and stuck
> I am not php expert but why are there two (( after your create table?
>
> -----Original Message-----
> From: Markus Jäntti [mailto:janmark@bodo.kommune.no]
> Sent: Wednesday, November 06, 2002 8:34 AM
> To: php-general@lists.php.net
> Subject: [PHP] New to PHP, and stuck
>
>
> I'm working myself through Julie C. Meloni's book "PHP" and now I'm
> stuck
at
> chapter 12.
> My script gives me this error: You have an error in your SQL syntax near
> '()' at line 1
> even tho I've even tried replacing my own work with the file from the
book's
> companion-files.
> I'd be very happy if someone would take the time to look through this and
> tell me what the problem might be. Hard to move forward when I don't
> understand this.
>
> Here's the script:
>
>
> <?
> //indicate the database you want to use
> $db_name ="testDB";
>
> //connect to database
> $connection = @mysql_connect("localhost","john","doe99") or
> die(mysql_error());
> $db = @mysql_select_db($db_name,$connection) or die(mysql_error());
>
> //start creating the SQL statement
> $sql ="CREATE TABLE $_POST[table_name] ((";
>
> //continue the SQL statement for each new field
> 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 .= ",";
> }
> }
>
> //clean up the end of the string
> $sql = substr($sql,0,-1);
> $sql .= ")";
>
> //execute the query
> $result = mysql_query($sql,$connection) or die(mysql_error());
>
> //get a good message for display upon success
> if ($result) {
> $msg ="<P>".$_POST[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 General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>