Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Problem with PHP and creating MySQL table

    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

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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

    Code:
    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
    )
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    yep --- desc in mysql is used for sorting ASCending or DESCending

  • #4
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •