I am currently working on a forum website with an upvote-system. However, there are some annoying, probably syntactic errors that are bugging me. I am talking about this piece of code.
<?php
session_start();
include_once 'dbh_discussion.inc.php';
$conn = db_discussion_connect();
$thread_id = $_POST['upvote'];
$sql1 = $conn->prepare("SELECT * FROM users WHERE user_id = '$_SESSION['u_id']' AND thread_id = '$thread_id'");
The things that aren't clear in this piece of code are as follows:
The error that I'm getting when debugging on the server:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/html/includes/thread_upvotes.inc.php on line 9
I feel like I'm missing out on something syntactical. Anyhow, I'd really appreciate someone telling me whats going wrong here.
Thanks
I get triggered so hard by this people who provide answers that are still wide open to Injections. Is it that difficult to change his prepared statement to something safe?!!!
Here a solution with a correct prepared statement. As if it takes that long to rewrite it. That should be against the rules here.
<?php
session_start();
include_once 'dbh_discussion.inc.php';
$conn = db_discussion_connect();
$sql1 = $conn->prepare("SELECT * FROM users WHERE user_id = :uid AND thread_id = :tid");
$sql1->bindParam(':uid', $_SESSION["u_id"]);
$sql1->bindParam(':tid', $_POST['upvote']);
$sql1->execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With