Hi
I’m trying out submission form and after clicking submit button the data is not inserted and the same page shows up with no errors. I assume that everything after if ($rateErr && $comErr && $catErr&& $linkErr && $priceErr == “”) is not executed. If i print the POST variables it shows all the proper array. Here’s the code:
[php]
<?php
// define variables and initialize with empty values
$nameErr = $comErr = $catErr =$priceErr =$linkErr ="";
$name = $description = $category = $price = $link = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//print_r($_POST);
if ($_POST["name"] == "") {
$nameErr = "Name the app";
}
else {
$name= $_POST["name"];
}
if ($_POST["price"] == "") {
$priceErr = "Price the app";
}
else {
$price= $_POST["price"];
}
if ($_POST["link"] == "") {
$linkErr = "Link the app";
}
else {
$link= $_POST["link"];
}
if ($_POST["category"] == "") {
$catErr = "Missing";
}
else {
$category = $_POST["category"];
}
if (empty($_POST["description"])) {
$comErr = "Missing";
}
else {
$description= $_POST["description"];
}
if ($rateErr && $comErr && $catErr&& $linkErr && $priceErr == "") {
try {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "INSERT INTO apps (app_name, category, price, link, description, date_added) VALUES (:name, :category, :price, :link, :description, :date)";
$stmt = $con->prepare( $sql );
$stmt->bindValue( ":name", $name);
$stmt->bindValue( ":category", $category);
$stmt->bindValue( ":price", $price);
$stmt->bindValue( ":link", $link);
$stmt->bindValue( ":description", $description);
$stmt->bindValue( ":date", now());
$stmt->execute();
echo "Submitted successfully";
}catch( PDOException $e ) {
echo $e->getMessage();
}
}
}
?>
[/php]