Forum Moderators: coopster

Message Too Old, No Replies

enum and unexpected TSTRING

a question regarding a TSTRING error, possibly related to enum category

         

Babylon Jasmine

4:01 am on Apr 25, 2007 (gmt 0)

10+ Year Member


I am attempting to set up a page to allow people to submit information about themselves via PHP and have it transfer automatically into an SQL database. I am starting by creating a test database to modify in order to be certain my program is working immaculately and have found myself unable to do so. I receive this error
Parse error: syntax error, unexpected T_STRING in /home/cornerst/public_html/maketestdb.php on line 18

which I understand is usually related to closing tags, quote marks, etc. However I could not find any open commands on the line before and line 18 includes ' marks to delineate the range of values available for an enum category. I have not created a table with an enum category before and am not sure if this could potentially be the problem. I have included the script below and any help would be greatly appreciated.

<?php
include 'config.php';
include 'opendb.php';

mysql_select_db('test') or die('Cannot select database');

$query = 'CREATE TABLE buyerinfo( '.
'cid INT NOT NULL AUTO_INCREMENT, '.
'cname VARCHAR(40) NOT NULL, '.
'cemail VARCHAR(40) NOT NULL, '.
'chomephone VARCHAR(40) NOT NULL, '.
'cworkphone VARCHAR(40), '.
'cotherphone VARCHAR(40), '.
'ctimetocall VARCHAR(40) NOT NULL, '.
'carea VARCHAR(40) NOT NULL, '.
'cpropertytype enum('Single Family Detached', 'Condo', 'Duplex - single unit', 'Duplex -

both units', 'Townhome', 'Mobile home', 'Multi-family 2-4 units', 'Multi-family 5 or

more') NOT NULL, '.
'cbedrooms TINYINT(4) NOT NULL, '.
'cagent enum('Yes', 'No') NOT NULL, '.
'cagreement VAR(40), '.
'crepairs VAR(40), NOT NULL, '.
'cpricerange VAR(40) NOT NULL, '.
'ccurrentpayments VAR(40) NOT NULL, '.
'cwhen enum('Today', '30 days', '3 months', 'No rush'), NOT NULL, '.
'ccredit enum('Good', 'OK', 'Bad'), NOT NULL, '.
'cownrent enum('Rent', 'Own') NOT NULL, '.
'ccomment VAR(40), '.
'PRIMARY KEY(cid))';

$result = mysql_query($query);

include 'closedb.php';
?>

Babylon Jasmine

5:40 am on Apr 25, 2007 (gmt 0)

10+ Year Member



ok, it was indeed the enums. I replaced the single quotes with double quotes and now it does not give me errors, however it also is not creating a table. I ran a shorter version earlier to be certain I could make tables and it worked without any problem. This however is not doing so.

capulet_x

5:48 am on Apr 25, 2007 (gmt 0)

10+ Year Member




change this...
$query = 'CREATE TABLE buyerinfo( '.

to this...
$query ( 'CREATE TABLE buyerinfo( '.

does that make a difference?

capulet_x

5:51 am on Apr 25, 2007 (gmt 0)

10+ Year Member



This is one of my own that worked for me...but I am using mySQL. I don't know if that makes a difference.

query("CREATE TABLE chat(
id INT(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
login VARCHAR(20) NOT NULL DEFAULT '',
message VARCHAR(255) NOT NULL DEFAULT '',
itstime VARCHAR(10) NOT NULL DEFAULT '')");

cameraman

6:11 am on Apr 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try escaping single quotes:
'cpropertytype enum(\'Single Family Detached\', ....

Babylon Jasmine

6:13 am on Apr 25, 2007 (gmt 0)

10+ Year Member



I tried the suggestion (replacing = with a parenthesis) and got this
Parse error: syntax error, unexpected ';' in /home/cornerst/public_html/maketestdb.php on line 29

I thought this might be because I had opened a parenthesis, without closing it. When I added a closed parenthesis at the end of the variable

((replacing 'PRIMARY KEY(cid))';
with 'PRIMARY KEY(cid))');

it gave me this error

Fatal error: Function name must be a string in /home/cornerst/public_html/maketestdb.php on line 9

I am using MySQL also.

capulet_x

7:14 am on Apr 25, 2007 (gmt 0)

10+ Year Member



Did you apply cameraman's advice? Were you able to work it out?