0

PHP:

<?php
    $con = mysqli_connect("localhost","root","","bookofexperiences");
    $sql2 ="SELECT Category_Title FROM category WHERE Category_ID=5";
    $query = mysqli_query($con, $sql2);
    $row = mysqli_fetch_assoc($query);
    $scategory = $row['Category_Title'];

    echo("<h3>". $scategory. "<h3/>");
    echo("<hr><br>");
?>

I want get different Category_ID when pressing different button. Now I'm using each button for different page which had only changed Category_ID. when I press a button, I got "Category_ID=5" and their content. When I press a another button, I got "Category_ID=6" and their content. But Now I used two different pages for this work. I want fix this one for one page. please help me how to fix this problem

1 Answers1

1

make the category id part of the url, then use $_GET to pull it into your query. So your url would be your domain.com/index.php?category=5

then you code would change to:

$sql2 = "SELECT Category_Title FROM category WHERE Category_ID='$_GET[category]'";
  • 3
    Look out for the SQL injection monster, http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1. – chris85 Jan 02 '16 at 16:54