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

  • SEARCH
  • Home
  • 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 9124495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:35:03+00:00 2026-06-17T06:35:03+00:00

I have two tables ( post , category ) CREATE TABLE post (pid INT(10)

  • 0

I have two tables ( post , category )

CREATE TABLE post    
(pid INT(10) NOT NULL AUTO_INCREMENT,    
post_title VARCHAR(255),   
post_result VARCHAR(255),  
post_content VARCHAR(500), 
cid INT(10), 
PRIMARY KEY (pid),
FOREIGN KEY (cid) REFERENCES category(cid));   

CREATE TABLE category (  
cid INT(10) NOT NULL AUTO_INCREMENT,  
cname VARCHAR(50),  
PRIMARY KEY (cid));  

This is my insert statement:

$id = isset($_POST['pid'])?$_POST['pid']:'';
$title=$_POST['post_title'];
$result=$_POST['post_result'];
$content=$_POST['post_content'];
$catid=$_POST['cid'];
$cat=$_POST['cname'];
$insertquery="INSERT INTO review (pid,post_title,post_result,post_content)
VALUES('','$title','$result','$content')";

Problem what im facing is, in my post table, the values of category id ( cid ) are NULL for every record.
How do make it to store the value of selected category.

This is my form:

<form id="create" action="insert.php" method="post">
<input type="text" name="post_title" placeholder="Title" /><br> 
<input type="text" name="post_result" placeholder="Final comment" /><br>
<textarea name="post_content" placeholder="Review" ></textarea><br>

    Category:
    <select name=cname>
    <option value="select"></option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
    <option value="4">Option 4</option>
    <option value="5">Option 5</option>
        </select><br><br>

<input class="submit" name="submit" type="submit" value="Submit"/>

</form>    

Do help in getting the output .

  • 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-17T06:35:04+00:00Added an answer on June 17, 2026 at 6:35 am

    First of all I hope that you populate your category select from db and value attribute contains category id. That being said it’s better to change name attribute to cid (because that what you expect in POST):

    <select name="cid">
    

    Then var_dump($_POST) will look like this:

    array(5) {
      ["post_title"]=>
      string(2) "aa"
      ["post_result"]=>
      string(2) "bb"
      ["post_content"]=>
      string(2) "cc"
      ["cid"]=>
      string(1) "2"
      ["submit"]=>
      string(6) "Submit"
    }
    

    Secondly you can ditch following php lines:

    $id = isset($_POST['pid'])?$_POST['pid']:'';
    $cat=$_POST['cname'];
    

    because you don’t send those values with the form and don’t use them.

    Thirdly you need to correct your insert statement

    $insertquery="INSERT INTO post (post_title,post_result,post_content,cid)
                  VALUES('$title','$result','$content','$catid')";
    

    Other considerations:

    • You better ensure on the client side that category name has been chosen, otherwise you’ll get error trying to insert the record in post.
    • As a1ex07 mentioned you need to check and sanitize all user input before you put in db
    • Switch to prepared statements
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: create table dbo.Dates ( Id int not null constraint Dates_Id_PK
I have two tables, Post and Category . Post pid title result content cid
I have two tables. Table 1. ======== id post -------- Table 2. ======== id
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 Table post_id post_name post_summary date post_reply Table parent_id post_id
I have a has_many :through association setup between two tables (Post and Category). The
I have two tables.. 1st Table: post |post_id | post_data | .......................... | 1
THE INFO Currently I have two tables I am working with- a POST table
I have two tables: table a ida valuea 1 a 2 b 3 c

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.