jquery - Trying to POST multiple items to the next page on form submit PHP
Get the solution ↓↓↓I'm a beginner with basic PHP knowledge. I have a multiple drop down menu item list that queries my database. On submit I would like to show the description of the item selected from the database.
My query
$cat3=$_GET['cat3'];
if(isset($cat3) and strlen($cat3) > 0){
$quer3="SELECT DISTINCT subcat2, detail FROM subcategory2 where subcat_id=$cat3 order by subcat2";
}else{$quer3="SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"; }
What's being posted on sumbit
echo "<select name='subcat3' ><option value=''>Select one</option>";
foreach ($dbo->query($quer3) as $noticia) {
echo "<option value='$noticia[subcat2]'>$noticia[subcat2]</option>";
}
echo "</select>";
Is it possible to pass my detail field along within subcat3 or do I have to create another table named details and another query ($quer4) and link it by the subcat2 id?
Any general information similar to an item search result(ebay) would help.
Answer
Solution:
Please consider using placeholders too rather than passing the GET param directly into your SQL - There's a good post here that I recommend you taking a look at:
How can I prevent SQL injection in PHP?
But - this should work (but isn't ideal)
SELECT DISTINCT subcat2
, detail
, ( SELECT cat3_descr
FROM subcategory3
WHERE subcat_id = ?
) AS cat3_descr
FROM subcategory2
WHERE subcat_id = ?
ORDER BY subcat2 ASC
This isn't perfect though as it's having to do an inline sub-query - it'd be better to JOIN it on your subcategory2 table, but I imagine you'd run into some GROUPing problems with your DISTINCT subcat2 (assuming it's not unique - in which case, do you need to group subcat2 at all?)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered in
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.