php - trying to find a solution for my undefined index -


i have table list of categories , have form search title of categories.

and im getting working want im having two notices im not able find solution few days.

i know if put @ before sql statments solve problem, think that´s not correct.

the search form working fine when pass value, when dont pass value have notice saying: "notice: undefined index: where", because select load list of categories done without having been passed value $_session['where'] used in sql statement.

somebody there see solution solve notices?

im having errors:

notice: undefined index: in "select * categories {$_session['where']}..."

and know im having errors because

my php code store in session sql statment user pass in search field:

if(isset($_post['sendform'])) { $search = $_post['search']; if(!empty($search) && $search != 'search...:') {     $_session['where'] = "where t '%$search%'";     header('location: index2.php?exe=posts/categories'); } else {     unset($_session['where']);     header('location: index2.php?exe=posts/categories'); } } 

then sql statment:

my php code sql statment:

$pag = (empty($_get['pag']) ? '1' : $_get['pag']); $max = 3;  $begin = ($pag * $max) - $max;  $readcategory = $pdo->prepare("select * categories {$_session['where']} order name desc limit :begin, :max"); $readcategory->bindparam(':begin', $begin, pdo::param_int); $readcategory->bindparam(':max', $max, pdo::param_int); $readcategory->execute();    $num_readcategory = $readcategory->rowcount();  if(!$num_readcategory >= 1) { echo 'there not categories yet'; } 

you should solve problem did $_get parameter:

$where = isset($_session['where']) ? $_session['where'] : ''; $readcategory = $pdo->prepare("select * categories {$where} order name desc limit :begin, :max"); 

also, encapsulate such access in function/method:

function get_session_param($name, $default = null) {    if (isset($_session[ $name ])) {        return $_session[ $name ];     }    return $default; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -