473,486 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to input content for particular topic to database in php?

36 New Member
I have recent topics displayed on my home page . When i click on any topic , it opens in a new page with full details of that topic . There is an option( a form ) where users can write review for that particular topic .

What i am looking for is , how do i insert data for only that topic , like , on my home page , in recent topics section , i have to display number of reviews of that topic only .

What i thought is , to take that topic's id and insert . But i do not know how to do that .

This is my 1st table for Topics.
Expand|Select|Wrap|Line Numbers
  1. Topic_Id  -  1 , 2 , 3  
  2. Title  -  First Topic , Second Topic , Third Topic 
  3. Category_ID  -   3 , 1 , 1  
  4. Date  -   yyyy-mm-dd
  5.  
This is my 2nd table for Category.
Expand|Select|Wrap|Line Numbers
  1. Category_ID  -  1 , 2 , 3
  2. Category_name   -  PHP , MYSQL , PDO
  3.  
This is to input .
Expand|Select|Wrap|Line Numbers
  1. try 
  2.    {
  3.    $query = $conn->prepare("INSERT INTO `topics`     (title,category_id) VALUES  (:title,:category_id)");
  4.  
  5.    $query->execute(array(
  6.         'title'       => $_POST['title'],
  7.                                     'category_id' => $_POST['category_id'],
  8.                                     )); 
  9.         }
  10.  
  11. catch (PDOException $e) 
  12.    {
  13.    error_log($e->getMessage());
  14.    die($e->getMessage());
  15.    }
  16.  
This is to display on home page .
Expand|Select|Wrap|Line Numbers
  1.    $sql = "SELECT * FROM review ORDER by pid DESC limit  0,3";
  2.  
  3.    $q    = $conn->query($sql);
  4.  
  5.    $q->setFetchMode(PDO::FETCH_ASSOC);
  6.  
  7.    while($row = $q->fetch()){
  8.       echo $row['title'];
  9.       echo $row['username'];
  10.    }
  11.  
This is my 3rd table for inserting reviews .
Expand|Select|Wrap|Line Numbers
  1. Topic_ID  -  
  2. Rating  -  
  3. Review  -  
  4. User_ID  -
  5.  
Problem 1 : How do i input topic-id of a particular topic when user fills and submits form into 3rd table ?
Problem 2 : And is there a need of user-id in 1st table because there is also an option for user to insert topics ?
Problem 3 : How do i select number of reviews for a particular topic to display next to it on home page ?
Jan 24 '13 #1
3 1910
Rabbit
12,516 Recognized Expert Moderator MVP
We only allow one question per thread in this forum. Please split out questions 2 and 3 into a separate thread. I will respond to question 1 since that it the question in the title.

You will need to output the id to the page so you can pass that onto to page that will insert into the third table. You can use a hidden form element for that if you don't want to show the id on the page.
Jan 24 '13 #2
yateesh
36 New Member
In <input type="hidden" /> how do i get that id ?
Expand|Select|Wrap|Line Numbers
  1. <form action="ins.php" method="post">
  2.      <input type="hidden" ?? />
  3.      <input type="text" name="rating" />
  4.      <input type="text" name="review" />
  5.      <input name="submit" type="submit" value="Submit"/>
  6. </form>
  7.  
Jan 24 '13 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. <input name="userid" type="hidden" value="use php to output the id" />
Jan 24 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1564
by: Roderik | last post by:
Hi, When developing a website in general when should I choose to put content in a database. For menu options, settings, and listings like products it seems to be clear for me to put them in. But...
3
2080
by: Dave | last post by:
I would like to create an application which gives the user a grid type interface for input, but is not connected to a database. I would save the grid contents to an array for manipulation. Is...
1
4660
by: newhaven_lad | last post by:
Please could someone help, I have a Perl cgi script which works perfectly when run in a dos prompt, it connects to a database on my laptop and inserts a record. But when I use the internet browser...
1
2788
by: Harry.PharmTouch | last post by:
My company is seeking a software solution for the following scenario. Please let me know if you have any suggestions. We are a small consulting company that services nursing homes. We need to...
2
1034
by: shapper | last post by:
Hello, Is it possible to create a class in Asp.Net, give values to its properties and save it in a database for later retrieval? How can I do this? Thanks, Miguel
2
1256
by: Phaelle | last post by:
hello I am doing a search engine for a library and I would like to offer the users the possibility of choosing a kind of document (video, audio, music sheet...) thanks to a check box . But the...
0
1299
by: balean | last post by:
Hi guys, I need help. I am trying to extract data from XML file. I am using all the fucntions needed to parse the xml data every thing working fine, but what I am looking for is to take the string...
21
2056
by: fjm | last post by:
Hello everyone. :) I knew it wouldn't be very long before I was back with another question. I just created a login box on my site and I am having an issue with trying to echo an error back to...
1
1084
by: pompy | last post by:
I've cleared the MS Access data base and pasted something else in it, also closing the data base afterwords. Is there a possibility, to recover the cleared content after closing the MS Access?
2
2047
by: arianule | last post by:
hallo I am a bit new with asP.net and I want to use a webservice to add information to a database. It is easy enough to establish a connection with the database using a Web Method but to add...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.