Hi
I'm trying to post and validate a form but it doesn't seem to work and it doean't display any errors
Here's the code
<?php
include("config.php");
session_start();
?>
<?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();
}
}
}
?>
<html>
<head>
</head>
<body>
<form method="POST"
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<select name="rating">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<span class="error"><?php echo $rateErr;?></span>
<br />
<textarea rows="4" cols="50" name="comment" value="<?php echo htmlspecialchars($comment);?>">
Enter text here...</textarea>
<span class="error"><?php echo $comErr;?></span>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>