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
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.
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; } } ?>
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.
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; } } } } ?>