php - MySQL query updating depending on $_POST values -
i having trouble thinking out way update query depending on user $_post values. have user management search button, site administrator can search sites users. in example:
<div id="website_user_management_search_left"> <div id="website_user_management_search_left_leftside"> <p>name:</p> <p>surname:</p> <p>telephone:</p> <p>group:</p> <p>discount group:</p> </div> <div id="website_user_management_search_left_rightside"> <input type="text" name="#" value="#" id="usersearch_name"> <input type="text" name="#" value="#" id="usersearch_surname"> <input type="text" name="#" value="#"> <input type="text" name="#" value="#"> <input type="text" name="#" value="#"> <input type="submit" id="button_adminusersearch" value="search"> </div>
then after pressing "search" button ajax sends request retrieve results, how can handle dynamic query? example - if user presses "search" query like:
mysqli_query($dbconnect,"select * accounts");
for example - if user specifys $_post["name"] value, query like:
mysqli_query($dbconnect,"select * accounts name='".$_post["name"]."'");
problem - how can efficiently handle kind of query? dumb check values "isset" , make tons of query cases. hope understood problem , can out it, because it`s kinda hard explain it.
maybe you're looking :
if(empty($_post['name'])) { $name = null; } else $name = $_post['name'];
then in statement, condition :
where (name=:name or :name null)
if name isset, search name, else return true , query not affected
Comments
Post a Comment