I've been trying to build a comments section for my website using PHP5, however when I try to use the $_GET method it stores the wrong value in the database column.Originally I just used $_GET['pageid'] but that would store NULL instead of an integer and that was because $_GET['pageid'] had a string datatype.
I then began to use (int)$_GET['pageid'] which would store an integer but the wrong value. It would store 0 every time. I know other people have had the same problem as me but I found no viable solution.
I am able to retrieve comments from my database and post them to their respective pages using $_GET['pageid'] after manually inserting integers in the pageID column.
If it makes any difference I am using Webmatrix 3 with MySQLi and PHP5. Thanks in advance!
if (isset($_POST['submit']))
{
$pageid = (int)$_GET['pageid'];
$username = $_SESSION['username'];
$comment = $_POST['comment'];
$query = "INSERT INTO comments (pageID, username, comment) VALUES (?, ?, ?)";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('iss', $pageid, $username, $comment);
$statement->execute();
$statement->store_result();
if ($statement->error)
{
die('Database query failed: ' . $statement->error);
}
$creationWasSuccessful = $statement->affected_rows == 1 ? true : false;
if ($creationWasSuccessful)
{
header ("Location: index.php");
}
}