please look at this PHP code?

  • Thread starter Thread starter blackmoonwhitesun
  • Start date Start date
B

blackmoonwhitesun

Guest
how can i combine this one:
if(isset($_GET['show_cat']) && preg_match('/^[1-9]{1}[0-9]{0,}$/', $_GET['show_cat']))
{
$category = $_GET['show_cat'];
}
else
$category = 1;

with this one?
<?PHP
if($_POST['do'] == "search" or $_GET['dosearch'] == "yes"){ $subaction = "search"; $dosearch = "yes"; include("./search.php"); }
else{$number= 1; include("./show_news.php"); }
?>

i tried this but it doesnt work :/ :
<?PHP

if(isset($_GET['show_cat']) && preg_match('/^[1-9]{1}[0-9]{0,}$/', $_GET['show_cat']))
{
$category = $_GET['show_cat'];
}
else
$category = 1;

if($_POST['do'] == "search" or $_GET['dosearch'] == "yes"){ $subaction = "search"; $dosearch = "yes"; include("./search.php"); }
else{$number= 1; include("./show_news.php"); }
?>

thank u
 
One thing, when using $_GET or $_POST, using the isset is unnessacery in a "if". Since if($_GET['something']) will check the get for the value, a null value will return false.
Try this code in your script, with some changes (the isset is not the problem, was just giving you a pointer.)
You may also want to get into the habit of using brackets more often, it will stop some confusion for both you, and the parser.
<?
if(isset($_GET['show_cat']) && preg_match('/^[1-9]{1}[0-9]{0,}$/', $_GET['show_cat'])){
$category = $_GET['show_cat'];
}else{
$catergory = 1;
}
if($_POST['do'] == "search" or $_GET['dosearch'] == "yes"){ $subaction = "search";
$dosearch = "yes";
include("./search.php");
}else{
$number = 1;
include("./show_news.php");
}
?>
Also, both of your scripts are independant (from my glance at it) from each other, so one technically shouldn't affect the other unles one has a parsing error (typo).
Secondly, if the script above does not work, my other suggesting would be (still using the script above), putting numerals inside quotes (ie $category = "1"; )
Good Luck!
 
Back
Top