Quote:
|
Originally Posted by GJay
PHP Code:
$select = "select * from orderinfo and day <>'' " ;
$whereClause = "";
if(isset($pon))
$where.='pon='.mysql_real_escape_string($pon).' AND';
if(isset($telephone))
$where.='telephone='.mysql_real_escape_string($telephone).' AND';
if(isset($order))
$where.='order='.mysql_real_escape_string($order).' AND';
if($where!='')
$where=' WHERE '.substr($where,0,-4);
$select.=$where;
$res = $db_connection->Execute($select);
|
Don't want to sound pushy, but there are a couple of other ways to do this.
PHP Code:
$select = "select * from orderinfo and day <>'' " ;
$whereClause = "";
if(!empty($pon))
$where.='pon='.mysql_real_escape_string($pon).' AND';
if(!empty($telephone))
$where.='telephone='.mysql_real_escape_string($telephone).' AND';
if(!empty($order))
$where.='order='.mysql_real_escape_string($order).' AND';
if($where!='')
$where=' WHERE '.substr($where,0,-4);
$select.=$where;
$res = $db_connection->Execute($select);
by using the empty function you stop someone from entering blank characters in a form which would not get caught by isset, and would trigger an error.
Although, If your a fan of arrays... You might try this.
PHP Code:
$select = "select * from orderinfo and day <>'' " ;
if(count($_GET) > 3){
exit; // Someone is trying to inject get variables!
}
elseif(count($_GET) > 1){
foreach($_GET as $x => $y){
$arr_where[] = "(`" . $x . "` LIKE '" . $y . "')";
}
$str_where = implode(" AND ",$arr_where);
$select .= " WHERE " . $str_where;
}
This would allow for scalability. If suddenly you need to ask for more information, It is all still optional just change the 3 in the first if statement to the total number of items your form should return.