Results 1 to 2 of 2

Thread: much needed help with the following code:

  1. #1

    Thread Starter
    Lively Member fundean's Avatar
    Join Date
    Apr 2001
    Posts
    98

    much needed help with the following code:

    <?php
    $db_host = "mysql";
    $db_user = "lefteh";
    $db_pwd = "1234";
    $db_name = "MyDB";
    mysql_connect($db_host, $db_user, $db_pwd);
    mysql_select_db($db_name);
    ?>
    <html>
    <head>
    <title>My first MySQL form submission</title>
    </head>
    <body>
    <?php
    if (!isset($_POST['submit'])) {
    ?>
    <form action="" method="post">
    Name: <input type="text" name="name"><br>
    Favorite Color: <input type="text" name="color"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>
    <?php
    } else {
    $name = $_POST['name'];
    $color = $_POST['color'];
    mysql_query("INSERT INTO `colors` (name, favoriteColor) VALUES
    ('$name', '$color')");
    echo "Success! Your favourite colour has been added!";
    }
    ?>
    </body>
    </html>

    When I submit the form using the values "fundean" and "blue" I get the following errors:

    "Error: method not allowed"

    HELP !!!!

    fundean

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: much needed help with the following code:

    uhh.. your host name is "mysql"? unless you edited it, that might be the problem?

    add some "or die()" statements to your code whenever you call a function, just to tell you where it broke.. ie:
    PHP Code:
      mysql_connect($db_host$db_user$db_pwd) or die('could not connect to mysql server');
      
    mysql_select_db($db_name) or die('could not select database'); 
    including your mysql_query() statement, too.

Posting Permissions

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



Click Here to Expand Forum to Full Width