PHP search mysql database with categories using GET -
as new project tried creating webshop see how works. display new items on sale in main div using php , select tag. , i'm able display items category when user clicks on category in sidebar. when user clicks sidebar page reloaded url adds ?category=car or other category. after use $_get['
if(isset($_get['category'])){ $testsearch = htmlspecialchars($_get['category']); $sqlselect = "select * items_sale inner join item_list on items_sale.item_id = item_list.item_id inner join user_list on items_sale.user_id = user_list.user_id inner join categories on items_sale.categorie_id = categories.category_id category = '$testsearch'"; }else{ $sqlselect = "select * items_sale inner join item_list on items_sale.item_id = item_list.item_id inner join user_list on items_sale.user_id = user_list.user_id inner join categories on items_sale.categorie_id = categories.category_id"; }
what can't seem work add search bar user can search seller's name or name of item while staying within selected category.
is there simple way this? because can think of bunch of if statements within each other see option selected. if there better options simple search system or more secure thats fine of course. how i've been doing far
here screenshot of current table btw
firstly, recommand don't put chars in url, id. it's safer, simplier , no error url encoding or else. , have cast id get. quicker search in mysql database id string :)
for question, can put category name (or id :) ) in form input hidden.
example :
<form> <input type="text" id="seller_name"> <input type="hidden" id="category" value="<?php echo (int)$_get['category']?>"> </form>
on server side, when receive request, check category , seller's name in sql request (with 2 if example...)
Comments
Post a Comment