Fishcakes Posted April 2, 2021 Share Posted April 2, 2021 (edited) SOLVED: I'm having trouble with an SQL query via php in building my Viewthread.php file So on the main page you have a list of the Threads and the link I created is like the below <h2><a href='viewthread.php?id='{$row['id']}'> {$row['Title']} </a></h2> Post {$row['id']}<br> If I set the query to an ID that exists the page loads fine $query = mysqli_query($conn, "SELECT * FROM Threads where id='156'") however if I set the id to the GET command the page doesn't load (which should've got the id) $query = mysqli_query($conn, "SELECT * FROM Threads where id=$_GET['id']") I tried casting this to a variable first too $Number = "$_GET['id']" $query = mysqli_query($conn, "SELECT * FROM Threads where id='$Number'") Edited April 2, 2021 by Fishcakes Quote Link to comment https://forums.phpfreaks.com/topic/312413-solved-building-my-viewthreadphp-page-on-a-forum/ Share on other sites More sharing options...
Fishcakes Posted April 2, 2021 Author Share Posted April 2, 2021 Figured it out! Just had to use Intval to cast it $number = intval($_GET['id']) ; Quote Link to comment https://forums.phpfreaks.com/topic/312413-solved-building-my-viewthreadphp-page-on-a-forum/#findComment-1585573 Share on other sites More sharing options...
Barand Posted April 2, 2021 Share Posted April 2, 2021 It sounds like $_GET['id'] does not have a value. If you want a list of threads, why are you selecting them individually? You should be using prepared statements and not placing user supplied data directly into the query Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/312413-solved-building-my-viewthreadphp-page-on-a-forum/#findComment-1585574 Share on other sites More sharing options...
Barand Posted April 2, 2021 Share Posted April 2, 2021 21 minutes ago, Fishcakes said: Just had to use Intval to cast it That is getting the query to run by changing a blank value to "0" thus preventing a syntax error. You should be checking that $_GET['id'] has a value before calling the query Quote Link to comment https://forums.phpfreaks.com/topic/312413-solved-building-my-viewthreadphp-page-on-a-forum/#findComment-1585575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.