...

View Full Version : Problem with PHP and creating MySQL table



MrShed
06-02-2004, 10:15 PM
Hi, I'm quite new to PHP but think I've picked it up quite quickly. However for some reason the following piece of code will not work...can any1 help please?


<?php

include('header.inc.php');

include('dbconnect.php');

mysql_query("DROP TABLE IF EXISTS properties");

if(! mysql_query("CREATE TABLE properties (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
bedrooms INT,
address TEXT,
desc TEXT,
rent DOUBLE,
area TEXT,
submitted TIMESTAMP,
picture BLOB,
username TEXT)"))
{
echo "couldnt be reset";
}

echo "Database reset";

include('footer.inc.php');
?>


It connects fine to the MySQL database, and doesn't throw me any error messages or anything, but when I come to look at the database the table just isn't there! Thanks in advance

firepages
06-03-2004, 02:56 AM
you need to ask for the error messages ..
try adding <?echo mysql_error();?> after each SQL call

though pretty sure here its the 'desc' fieldname which though I do not think is a MySQL reserved word still causes me issues from time to time , to counter it (and its good practice anyway) enclose the fieldnames with backticks ... I just did `desc` here but you can do them all



CREATE TABLE properties(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
bedrooms INT,
address TEXT,
`desc` TEXT,
rent DOUBLE,
area TEXT,
submitted TIMESTAMP,
picture BLOB,
username TEXT
)

litebearer
06-03-2004, 04:17 AM
yep --- desc in mysql is used for sorting ASCending or DESCending

MrShed
06-03-2004, 08:45 AM
ohh..I didn't know that, thanks! But, that's not the problem, because when that didnt work, I tried just adding a basic 2 field table username TEXT, password TEXT, and it wouldn't let me do that either. So I'm not sure what it is, but any ideas and let me know!!! Thanks

MrShed
06-03-2004, 08:51 AM
ok ive tried changing desc to description and it works!!!! No idea why my basic 1 failed b4 then. Thanks for all the help guys much appreciated



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum