Hi
I’m trying to validate and submit a form in a page which content is generated by passing ID through URL.
I want the form to be visible only if the user is logged in but the whole thing doesn’t work. If you could explain what I’m doing wrong that would be great. ^^
the code for the template page:
[php]<?php
// define variables and initialize with empty values
$rateErr = $comErr = “”;
$rating = $comment = “”;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($_POST["rating"] == "") {
$rateErr = "Rate the app";
}
else {
$rating= $_POST["rating"];
}
if (empty($_POST["comment"])) {
$comErr = "Missing";
}
else {
$comment = $_POST["comment"];
}
if ($rateErr && $comErr == "") {
try {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "INSERT INTO reviews (rating, content, appID, user) VALUES(:rating, :comment, :appID, :username)";
$stmt = $con->prepare( $sql );
$stmt->bindValue( ":rating", $rating);
$stmt->bindValue( ":comment", $comment);
$stmt->bindValue( ":appID", $_GET['id']);
$stmt->bindValue( ":username", $_SESSION['username']);
$stmt->execute();
return "Submitted successfully";
}catch( PDOException $e ) {
return $e->getMessage();
}
}
}
?>
"> <?php if ($_SESSION["loggedIn"]) { include("form.php"); } else { echo "You need to login to review this app"; } ?> [/php]and the form.php
[php]
Enter text here…
<?php echo $comErr;?>
[/php]