Jump to content

SOLVED Building my Viewthread.php page on a forum

Recommended Posts

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 by Fishcakes
Link to post
Share on other sites
  • Fishcakes changed the title to SOLVED Building my Viewthread.php page on a forum

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.

Link to post
Share on other sites
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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.