Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9135599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:50:45+00:00 2026-06-17T08:50:45+00:00

I have two tables, Post and Category . Post pid title result content cid

  • 0

I have two tables, Post and Category.

Post

   pid   title    result    content      cid   
   1    Option1    Opt      content1      2   
   2    Option2    Opt      content2      2   
   3    Option3    Opt      content3      3   

Category

   cid  cname   
   1     Cat 1    
   2     Cat 2    
   3     Cat 3   

This is my insert.php .

mysql_connect('localhost','root','');

mysql_select_db("database") or die("Unable to select database");

$title=$_POST['post_title'];
$result=$_POST['post_result'];
$content=$_POST['post_content'];
$sid=$_POST['cid'];
$date=$_POST['date'];

$insertquery="INSERT INTO review (post_title,post_result,post_content,cid,date)
          VALUES('$title','$result','$content',$sid,NOW())";


$result=mysql_query($insertquery);

if(! $result )
{
  die('Could not enter data: ' . mysql_error());
}
else {

        echo "Entered data successfully\n";
        header('Location:home.php');
    }    

This is my cat.php which displays posts of particular category.

$link = mysql_connect("localhost","root","");
mysql_select_db("database");



$query="SELECT * FROM category WHERE cid='$cid'";

 $result = mysql_query($query) or die("Query to get data failed with error:  ".mysql_error());

while($row = mysql_num_rows($result)) { 
echo    //details goes here

}    

This is my category menu list on home page .

<ul>            
<li><a class="my-button" href="#">Cat 1</a></li>
<li><a class="my-button" href="#">Cat 2</a></li>
<li><a class="my-button" href="#">Cat 3</a></li>
</ul>    

This is javascript.

<script>
$(document).ready(function() {
$('body').on('click', '.my-button', function() {

   $("#display").load("cat.php");

   });
});
</script>    

Everything is getting inserted to database correctly . But im not able to display the posts of specific category onclick.

I have given the complete code. What I want is, when I click on Cat 1 or Cat 2 or Cat 3 on home page I need to display all data from post table of the selected category in the #display div.

I am getting an error saying:

cid is undefined variable

Please help me find the proper code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:50:45+00:00Added an answer on June 17, 2026 at 8:50 am

    that is because looking at your script $cid, which is used in your query is not defined anywhere. Kudos for at least ahving error reporting on. Next time you really should read and understand the error messages you get, as this oftentimes tells you exactly what the problem is.

    Also, you really need to look at learning mysqli or PDO. The mysql_* are depreacted and should no longer be used. You also have sever SQL injection vulnerability, so you should read up on what to do about that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables ( post , category ) CREATE TABLE post (pid INT(10)
I have a has_many :through association setup between two tables (Post and Category). The
I have two tables. Table 1. ======== id post -------- Table 2. ======== id
I have two tables; one with post data and in the other each row
I have two tables, Subject and Content, where Content references Subject with foreign key.
Okay so I have two tables, a category table and a posts table. I
I have two tables Posts and comments Post Table Post_id Post_content Comments table comment_id
I have two tables Post (id, ..., creationdate) and Post_Has_Post(parent_id, child_id) . Some Posts
I have two tables: posts - holds post information listen - holds information on
I have two tables:user and post and the structures of them are: post: +---------+----------+------+-----+---------+----------------+

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.