Jump to content

dave25

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by dave25

  1. Is this good way to check if return variable is detected and return contains page where it actually came from? PHP $get['return'] = 'do%3DnewsManagement%26search%3D%26sort%3Did%26order%3DDESC'; SMARTY HTML {if !empty($get.return) && strpos($get.return, 'do%3DnewsManagement') !== false} <li><a href="index.php?{$get.return|urldecode}">News Management</a></li> {/if}
  2. Why i get 2 error message if it can find my file? Warning: require(includes/paginator/index1.php): failed to open stream: No such file or directory in C:\xampp\htdocs\testScript\admin\index.php on line 15 Fatal error: require(): Failed opening required 'includes/paginator/index1.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\testScript\admin\index.php on line 15 index.php <?php ob_start(); session_start(); define('testScript', 1) error_reporting(E_ALL); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); ini_set('html_errors', TRUE); ini_set('log_errors', TRUE); ini_set('error_log', dirname(__FILE__).'/php-errors.log'); require 'includes/paginator/index_1.php';# Added _1 to index.php to force error. ...................... ...................... ob_flush(); ?>
  3. After thinking a lot i came up with this working solution. Removed $arrow and reverse. Replaced with.. function sortReverse($sort, $match, $order){ if($sort == $match){ if($order == 'DESC') return 'ASC'; else return 'DESC'; }else{ return 'ASC'; } } function sortArrow($sort, $match, $order){ if($sort == $match && $order == 'ASC') return 'files/images/table/sort_asc.png'; else if($sort == $match && $order == 'DESC') return 'files/images/table/sort_desc.png'; else return 'files/images/table/sort_both.png'; } And table code print ' <table width="500px" border="1"> <tr> <td><a href="index.php?do=test2&sort=id&order='.sortReverse($sort, 'id', $order).'">ID<img src="'.sortArrow($sort, 'id', $order).'"></a></td> <td><a href="index.php?do=test2&sort=country_code&order='.sortReverse($sort, 'country_code',$order).'">Country Code<img src="'.sortArrow($sort, 'country_code', $order).'"></a></td> <td><a href="index.php?do=test2&sort=country_name&order='.sortReverse($sort, 'country_name',$order).'">Country Name<img src="'.sortArrow($sort, 'country_name', $order).'"></a></td> </tr>'; .....
  4. Basically its working. But still some issues. Without Sort with ID clicked. Everything is okey. <tr> <td><a href="index.php?do=test2&sort=id&order=ASC">ID<img src="files/images/table/sort_both.png"></a></td> <td><a href="index.php?do=test2&sort=country_code&order=ASC">Country Code<img src="files/images/table/sort_both.png"></a></td> <td><a href="index.php?do=test2&sort=country_name&order=ASC">Country Name<img src="files/images/table/sort_both.png"></a></td> </tr> Cliked ID. Not expected html output. <tr> <td><a href="index.php?do=test2&sort=id&order=DESC">ID<img src="files/images/table/sort_asc.png"></a></td> <td><a href="index.php?do=test2&sort=country_code&order=DESC">Country Code<img src="files/images/table/sort_asc.png"></a></td> <td><a href="index.php?do=test2&sort=country_name&order=DESC">Country Name<img src="files/images/table/sort_asc.png"></a></td> </tr> Should be. <tr> <td><a href="index.php?do=test2&sort=id&order=DESC">ID<img src="files/images/table/sort_asc.png"></a></td> <td><a href="index.php?do=test2&sort=country_code&order=ASC">Country Code<img src="files/images/table/sort_both.png"></a></td> <td><a href="index.php?do=test2&sort=country_name&order=ASC">Country Name<img src="files/images/table/sort_both.png"></a></td> </tr>
  5. Problem with $reverse and $arrow. Always same value. <?php $get = array( 'sort' => NULL, 'order' => NULL, 'search' => NULL ); if(!empty($_GET)){ $defs = array( 'sort' => FILTER_SANITIZE_STRING, 'order' => FILTER_SANITIZE_STRING, 'search' => FILTER_SANITIZE_STRING ); $get = filter_input_array(INPUT_GET, $defs); } $sort = in_array($get['sort'], array('id', 'country_code', 'country_name')) ? $get['sort'] : 'id'; $order = in_array($get['order'], array('ASC', 'DESC')) ? $get['order'] : 'ASC'; $reverse = ($order == 'DESC' ? 'ASC' : 'DESC'); $arrow = ($sort == $get['sort'] and $order == 'ASC') ? 'files/images/table/sort_asc.png' : ($sort == $get['sort'] and $order == 'DESC') ? 'files/images/table/sort_desc.png' : 'files/images/table/sort_both.png'; $query = 'SELECT * FROM country WHERE CONCAT_WS("|", id ,country_code, country_name) LIKE :search ORDER BY '.$sort.' '.$order.''; $select = $db->prepare($query); $select->bindValue(':search', '%'.$get['search'].'%', PDO::PARAM_STR); $select->execute(); print ' <table width="500px" border="1"> <tr> <td><a href="index.php?do=test2&sort=id&order='.$reverse.'">ID<img src="'.$arrow.'"></a></td> <td><a href="index.php?do=test2&sort=country_code&order='.$reverse.'">Country Code<img src="'.$arrow.'"></a></td> <td><a href="index.php?do=test2&sort=country_name&order='.$reverse.'">Country Name<img src="'.$arrow.'"></a></td> </tr>'; while($row = $select->fetch(PDO::FETCH_ASSOC)){ print ' <tr> <td>'.$row['id'].'</td> <td>'.$row['country_code'].'</td> <td>'.$row['country_name'].'</td> </tr>'; } print ' </table>'; ?>
  6. I have tried with this way and its working and also dosent display any undefined indexes. $input_POST = array( 'a' => NULL, 'b' => NULL, 'e' => NULL ); $input_GET = array( 'c' => NULL, 'd' => NULL ); $input = array_merge($input_POST, $input_GET); if(!empty($_GET)){ $defs_GET = array( 'c' => FILTER_SANITIZE_STRING, 'd' => FILTER_SANITIZE_NUMBER_INT ); $input_GET = filter_input_array(INPUT_GET, $defs_GET); } if(!empty($_POST)){ $defs_POST = array( 'a' => FILTER_SANITIZE_STRING, 'b' => FILTER_SANITIZE_NUMBER_INT, 'e' => array('filter' => FILTER_SANITIZE_NUMBER_INT, 'flags' => FILTER_REQUIRE_ARRAY) ); $input_POST = filter_input_array(INPUT_POST, $defs_POST); } $input = array_merge($input_POST, $input_GET); if(filter_has_var(INPUT_POST, 'submit')){ if(empty($input['a'])) { $errors[] = 'Error a.'; ..........................................................
  7. How to filter input in array and declare all variables to prevent undefined index. I know how to use filter_input_array(INPUT_POST, ...) and filter_input_array(INPUT_GET, ...) separately, but i donk know how to use them together. Current code for testing. <?php $errors = array(); /* FILTER AND DECLARE VARIABLES */ $input['a'] = isset($_POST['a']) ? filter_input(INPUT_POST, 'a', FILTER_SANITIZE_STRING) : NULL; $input['b'] = isset($_POST['b']) ? filter_input(INPUT_POST, 'b', FILTER_SANITIZE_NUMBER_INT) : NULL; $input['c'] = isset($_GET['c']) ? filter_input(INPUT_GET, 'c', FILTER_SANITIZE_STRING) : NULL; $input['d'] = isset($_GET['d']) ? filter_input(INPUT_GET, 'd', FILTER_SANITIZE_NUMBER_INT) : NULL; $input['e'] = isset($_POST['e']) ? filter_input(INPUT_POST, 'e', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY) : NULL; /* $input = array( 'a' => NULL, 'b' => NULL, 'e' => NULL ); */ if(filter_has_var(INPUT_POST, 'submit')) { /* $defs = array( 'a' => FILTER_SANITIZE_STRING, 'b' => FILTER_SANITIZE_NUMBER_INT, 'e' => array('filter' => FILTER_SANITIZE_NUMBER_INT, 'flags' => FILTER_REQUIRE_ARRAY ) ); */ if(empty($input['a'])) { $errors[] = 'Error a.'; } if(empty($input['b'])) { $errors[] = 'Error b.'; } } if(filter_has_var(INPUT_POST, 'submit') and empty($errors)) { /* QUERYES */ print 'SUCCESS'; } if(count($errors)) { foreach($errors as $error) { print $error; } } print " <form method='post'> A: <input type='text' name='a' value='".$input['a']."'> POST STRING <br> B: <input type='text' name='b' value='".$input['b']."'> POST INT <br> C: <input type='text' readonly value='".$input['c']."'> GET STRING <br> D: <input type='text' readonly value='".$input['d']."'> GET INT <br> <input type='submit' name='submit' value='SUBMIT'> </form>"; ?>
  8. How do add $_GET['return'] to get output $input['return'] like i have $input['username'] and add value null if no return url detected? <?php $errors = array(); /* Form is not submitted */ $input = array( 'username' => NULL, 'password' => NULL, 'remember' => NULL ); /* Form is submitted */ if(filter_has_var(INPUT_POST, 'submit')){ $defs_POST = array( 'username' => FILTER_SANITIZE_STRING, 'password' => FILTER_UNSAFE_RAW, 'remember' => FILTER_SANITIZE_STRING ); $input = filter_input_array(INPUT_POST, $defs_POST); if(empty($input['username'])){ $errors[] = 'Please enter your username.'; } if(empty($input['password'])){ $errors[] = 'Please enter your password.'; } } if(filter_has_var(INPUT_POST, 'submit') and empty($errors)){ print "Username = '".$input['username']."', Password = '".$input['password']."', Remember = '".$input['remember']."', Return = '".$input['return']."'"; /* if(!empty($input['return'])) redirect(urldecode($input['return'])); else redirect('index.php?do=home'); */ } print " <form method='post'> Username <input type='text' name='username' value='".$input['username']."'><br> Password <input type='text' name='password' value='".$input['password']."'><br> Remember me <input type='checkbox' name='remember' value='Yes'><br> <input type='submit' name='submit' value='SUBMIT'> </form>"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.