Basic Form

Discussion in 'PHP' started by epm1013, Mar 1, 2008.

  1. #1
    I'm working with a book called "PHP Solutions" by David Powers.

    I created a form exactly the way the book describes along with the php to put into my MySQL database. However, I get "Method Not Allowed The requested method POST is not allowed for the URL /index.html." when I try a test in the form. Can someone suggest where I might have went wrong in my coding? My page is www.bloggerinstitute.com
     
    epm1013, Mar 1, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    You have to define the action="" part of the form. It should point to the php which processes the form request.
    Since you left it blank, it is attempting to post to an html file. Thus an error.
     
    shallowink, Mar 1, 2008 IP
  3. epm1013

    epm1013 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you Shallowink,

    Since your suggestion, it toworked.

    I've since then have been able to figure out a few other errors on my own. However, this one has got me stumped.


    Parse error: parse error, unexpected $ in /home/content/e/p/m/epm1013/html/journal_insert_mysql.php.txt on line 26

    Here is the entire php code
    <?php
    if (array_key_exist('insert', $_POST)) {
    include('../includes/conn_mysql.inc.php');
    include('../includes/corefuncs.php');
    // remove backslashes
    nukeMagicQuote();
    //prepare an array of expected items
    $expected = array('title', 'article');
    // create database connection
    $conn = dbConnect('admin');
    // make $_POST data safe for insertion into database
    foreach ($_POST as $key => $value) {
    if (in_array($key, $expected)) {
    ${$key} = mysql_real_escape_string($value);
    // prepare the SQL query
    $sql= "INSERT INTO journal (title, article, created)
    VALUES('$title', 'article', NOW())";
    // process the query
    $result = mysql_query($sql) or die(mysql_error());
    // if successful, redirect to list of existing records
    if ($result) {
    header('Location: http://www.bloggerinstitute/php_uploads/journal_list.php');
    exit;
    }
    }
    ?>
     
    epm1013, Mar 1, 2008 IP
  4. swishman

    swishman Well-Known Member

    Messages:
    1,264
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #4
    oh...too late for me..
     
    swishman, Mar 1, 2008 IP
  5. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #5
    What is line 26 on journal_insert_mysql.php.txt?
     
    aaron_nimocks, Mar 1, 2008 IP
  6. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #6
    You are missing a } actually 2 }s . Have to close out the foreach and the if statement after it.
    That error unexpected $, usually means a } is missing and bad part is the line # will be EOF.
     
    shallowink, Mar 1, 2008 IP
  7. quicksolutions

    quicksolutions Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    it should be like this

    <?php
    if (array_key_exist('insert', $_POST))
    {
    include('../includes/conn_mysql.inc.php');
    include('../includes/corefuncs.php');
    // remove backslashes
    nukeMagicQuote();
    //prepare an array of expected items
    $expected = array('title', 'article');
    // create database connection
    $conn = dbConnect('admin');
    // make $_POST data safe for insertion into database
    foreach ($_POST as $key => $value)
    {
    if (in_array($key, $expected))
    {
    ${$key} = mysql_real_escape_string($value);
    // prepare the SQL query
    $sql= "INSERT INTO journal (title, article, created) VALUES
    ('$title', 'article', NOW())"; /// please check this out here should
    be 'article' or '$article'
    // process the query
    $result = mysql_query($sql) or die(mysql_error());
    // if successful, redirect to list of existing records
    if ($result)
    {
    header('Location: thesiteaddress');
    exit;
    }
    }
    }
    }
    ?>
     
    quicksolutions, Mar 2, 2008 IP