Forum Moderators: coopster

Message Too Old, No Replies

Our Back End Is Broken

         

GGR_Web

11:49 am on Nov 17, 2008 (gmt 0)

10+ Year Member



We have recently discovered a fault in our ecommerce backend.

At the minute the following code evalutes to "prob".

if($result = mysql_query(sprintf("SELECT subarumodels FROM product WHERE partno='%s'",$partno))){
if(mysql_num_rows($result) > 0){
$row = mysql_fetch_array($result);
$subarumodels = $row['subarumodels'];
if($subarumodels){
if(ereg(",",$subarumodels)){
$subarumodel = explode(",",$subarumodels);
}else{
$subarumodel[0] = $subarumodels;
}
}
}
}
$query = "SELECT id,name,door,yearfrom,yearto,shape,serialnumber,modeltype FROM subarumodel";
$wherebit = 0;
if($shape <> "ALL"){
$wherebit = 1;
$query .= " WHERE shape = '".$shape."'";
}
if($door){
if($wherebit == 0){
$query .= " WHERE ";
}else{
$query .= " AND ";
}
$query .= " door='".$door."'";
}
if($yearto && $yearfrom){
if($wherebit == 0){
$query .= " WHERE ";
}else{
$query .= " AND ";
}
//from needs to be between yearto-yearfrom and to needs to be before yearfrom
$query .= "((yearfrom<=".$yearfrom." AND yearto>=".$yearfrom.") OR ";
if($yearto <> 0){
$query .= "(yearfrom<=".$yearto." AND yearto>=".$yearto.") OR ";
$query .= "(yearfrom>".$yearfrom." AND yearto<".$yearto.") OR ";
}
if($yearto <> 0){
$query .= "(yearto=0 AND yearfrom<=".$yearto.")";
}else{
$query .= "(yearto=0)";
}
$query .= ")";
}
if($subarumodels){
if($wherebit == 0){
$query .= " WHERE ";
}else{
$query .= " AND ";
}
for($i=0;$i<count($subarumodel);$i++){
$query .= "id <> ".$subarumodel[$i];
if($i < (count($subarumodel)-1)){
$query .= " AND ";
}
}
}
$query .= " ORDER BY id";
if($result = mysql_query($query)){
if(mysql_num_rows($result) > 0){
$radiolist = "";
while($row = mysql_fetch_array($result)){
$radiolist .= $row['id'].",";
}
}
}
if($radiolist && $partno){
$query = "UPDATE product SET subarumodels = '";
if($subarumodels){
$query .= $subarumodels;
$commabit = ",";
}
$radioitem = explode(",",$radiolist);
for($i=0;$i<(count($radioitem)-1);$i++){
$query .= $commabit.$radioitem[$i];
$commabit = ",";
}
$query .= "' WHERE partno='".$partno."'";
//echo $query;
if(!mysql_query($query)){
echo "update failed";
}
}else{
echo "prob";
}
}

I think I've cuaught the relevant code here (so many if statments!) Assuming the page is broken, something is wrong in here somewhere.

eelixduppy

6:46 pm on Nov 17, 2008 (gmt 0)



Are you getting any errors in your error log from this script? Has this script worked in the past?