403 Forbidden Checkboxes PDO/PHP Syntax Issue PHPMYADMIN/WAMP
Ok, so I was following this tutorial, which who knows, may or may not be accurate. when I choose submit, I get a 403 error. and a screen with half the PHP code.
from where I am sitting it is a syntax error, but for the life of me, I cannot figure out why. I have run it through notepad++ phpdesigner and a few online checkers. most of them say it is fine, however the lint check shows an syntax error to begin with, beyond that I am stumped.
at first I thought the 403 error was permission based however I went back to another project and could add data to the PHPMYADMIN database, so that all checks out. I have posted the code below, so if someone wants to give it a glance and set me on the right path, that would be great.
for some reason I cannot get the mysqli to talk to my apache, so I am stuck with pdo options for projects. Havent figured out how to fix that issue as yet.
thanks
<?php
$fruitArray = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['btn_save']))
{ try
{ $dbcon = new PDO("mysql:host=localhost;dbname=my_db", 'root', 'password');
$dbcon->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch (PDOException $e) {echo $e->getMessage(); }
if(isset( $_POST['fruit']))
{ $values = array();
foreach($_POST['fruit'] as $selection )
{ if(in_array($selection, $fruitArray))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
} // end of foreach.
try // save user selection to the database
{ $DBH = $dbcon->prepare("INSERT INTO table_fruit
(orange, apple, grapefruit, banana, watermelon )
VALUES (:DBorange, :DBapple, :DBgrapefruit, :DBbanana, :DBwatermelon)");
$DBH->bindParam(':DBorange', $values['orange']);
$DBH->bindParam(':DBapple', $values['apple']);
$DBH->bindParam(':DBgrapefruit', $values['grapefruit']);
$DBH->bindParam(':DBbanana', $values['banana']);
$DBH->bindParam(':DBwatermelon', $values['watermelon']);
$DBH->execute();
} catch(PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); }
}
else
{ echo 'No checkbox selection made...'; }
} // End of, if statement from the button check
?>
<span style="font-family: arial,helvetica,sans-serif; font-size: 12px;">
<html>
<head>
<title>Checkbox selection using PHP (using PDO) and MySQL v2</title>
</head>
<body>
<h2>Pick your most favourite fruits:</h2>
<form name="fruitcheckbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="fruit[]" value="orange"> Orange
<input type="checkbox" name="fruit[]" value="apple"> Apple
<input type="checkbox" name="fruit[]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[]" value="banana"> Banana
<input type="checkbox" name="fruit[]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btn_save">
</form>
</body>
</html> </span>
AFTER HTML is EXECUTED. whether in IE, EDGE or CHROME.
setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); } catch (PDOException $e) {echo $e->getMessage(); } if(isset( $_POST['fruit'])) { $values = array(); foreach($_POST['fruit'] as $selection ) { if(in_array($selection, $fruitArray)) { $values[ $selection ] = 1; } else { $values[ $selection ] = 0; } } // end of foreach. try // save user selection to the database { $DBH = $dbcon->prepare("INSERT INTO table_fruit (orange, apple, grapefruit, banana, watermelon ) VALUES (:DBorange, :DBapple, :DBgrapefruit, :DBbanana, :DBwatermelon)"); $DBH->bindParam(':DBorange', $values['orange']); $DBH->bindParam(':DBapple', $values['apple']); $DBH->bindParam(':DBgrapefruit', $values['grapefruit']); $DBH->bindParam(':DBbanana', $values['banana']); $DBH->bindParam(':DBwatermelon', $values['watermelon']); $DBH->execute(); } catch(PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } } else { echo 'No checkbox selection made...'; } } // End of, if statement from the button check ?> Pick your most favourite fruits:
Orange Apple Grapefruit Banana Watermelon
and when I make a selection I get
http://localhost/my-site/insertintodbpdo/%3C?php echo $_SERVER['PHP_SELF']; ?> u don't have permission to access /my-site/insertintodbpdo/< on this server.
链接地址: http://www.djcxy.com/p/69172.html上一篇: 调用成员函数prepare()null