1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Bug?

Discussion in 'PHP' started by crazyhorse, May 7, 2005.

  1. #1
    Hi

    I think i got a bug in my php code. Im wondering whether someone can help me to fix this. The script checks on bases on a zipcode what information it should send. Since there have been some changes, people receive the wrong info (wrong zipcode) when they signup at my site and enter their zipcode. So lets say i signup with the zipcode 1555as i get info emailed for the zipcode 2555as.

    Anyone here that would like to take a look at ir. The code is:
    
    //////////////////////////////////////////////////////
    				// Find Advisor in zip code
    				//////////////////////////////////////////////////////
    				$resultAd = executeQuery("SELECT * FROM ".PREFIX."ADVISOR_ZIPCODE WHERE ZIPCODE LIKE '".substr($zip, 0, 3)."%'");
    				$resTot = getTotalRows($resultAd);
    
    				if ( $resTot > 1 )
    				{
    					$adIn = "";
    					while ( $rowAd = getRow($resultAd) )
    						$adIn .= "'".$rowAd["ADVISORID"]."', ";
    
    					// Select the advisor least assigned
    					//echo "<br>SELECT A.ADVISORID , COUNT(MEMBERID) AS TOT FROM ".PREFIX."ADVISOR A LEFT OUTER JOIN ".PREFIX."ADVISOR_ASSIGNED AA ON AA.ADVISORID = A.ADVISORID  WHERE A.ADVISORID IN (".$adIn." 0) GROUP BY A.ADVISORID ORDER BY TOT LIMIT 1<br>";
    					$resultAd = executeQuery("SELECT A.ADVISORID , COUNT(MEMBERID) AS TOT FROM ".PREFIX."ADVISOR A LEFT OUTER JOIN ".PREFIX."ADVISOR_ASSIGNED AA ON AA.ADVISORID = A.ADVISORID  WHERE A.ADVISORID IN (".$adIn." 0) GROUP BY A.ADVISORID ORDER BY TOT LIMIT 1");
    
    					if ( $rowAd = getRow($resultAd) )
    					{
    						//echo "INSERT AFTER MULTIPLE <BR>";
    						//echo "INSERT INTO ".PREFIX."ADVISOR_ASSIGNED VALUES (".getNextId("ADVISOR_ASSIGNED").", '".$rowAd["ADVISORID"]."', '".$max."', NOW() )<br>";
    						executeUpdate("INSERT INTO ".PREFIX."ADVISOR_ASSIGNED VALUES (".getNextId("ADVISOR_ASSIGNED").", '".$rowAd["ADVISORID"]."', '".$max."', NOW() )");
    					}
    
    					$advisorId = $rowAd["ADVISORID"];
    				}
    				else if ( $resTot == 1 )
    				{
    					if ( $rowAd = getRow($resultAd) )
    					{
    						//echo "INSERT AFTER SINGLE <BR>";
    						//echo "INSERT INTO ".PREFIX."ADVISOR_ASSIGNED VALUES (".getNextId("ADVISOR_ASSIGNED").", '".$rowAd["ADVISORID"]."', '".$max."', NOW() )<br>";
    						executeUpdate("INSERT INTO ".PREFIX."ADVISOR_ASSIGNED VALUES (".getNextId("ADVISOR_ASSIGNED").", '".$rowAd["ADVISORID"]."', '".$max."', NOW() )");
    						$advisorId = $rowAd["ADVISORID"];
    					}
    				}
    				else
    				{
    					$advisorId = 0;
    				}
    
    				//echo "UPDATE ".PREFIX."MEMBER SET ADVISORID = '".$advisorId."' AND VERIFICATION_CODE = '1' AND ISVALID = 'Y' WHERE MEMBERID = '".$max."'";
    				executeUpdate("UPDATE ".PREFIX."MEMBER SET ADVISORID = '".$advisorId."' AND VERIFICATION_CODE = '1' AND ISVALID = 'Y' WHERE MEMBERID = '".$max."'");
    				executeUpdate("UPDATE ".PREFIX."MEMBERINFO SET ADVISORID = '".$advisorId."'  WHERE EMAIL = '".$email."'");	
    
    				//////////////////////////////////////////////////////
    				//Send Email with Advisor info
    				//////////////////////////////////////////////////////
    				$bodyInfo = NAME." : ".$fname." ".$lname."<br>".EMAIL." : ".$email."<br>".GENDER." : ".$gender."<br>".ADDRESS." : ".$address."<br>".ZIP." : ".$zip."<br>".CITY." : ".$city."<br>".PHONE_NO." : ".$phone."<br>".HEIGHT." : ".$heightsft.METER." ".$heights.CM."<br>".WEIGHT." : ".$weight."<br>".AGE." : ".$age."<br>IP Address : ".$_SERVER["REMOTE_ADDR"]."<br>";
    
    				if ( $advisorId )
    				{
    					
    					$row			= getRecord("ADVISORINFO", $advisorId, "ADVISORID");
    					$advisorDetails = FOLLOWING_ARE_THE_DETAILS_ADVISOR."<br><br>".NAME.": ".$row["NAME"]."<br>".ADDRESS.": ".$row["ADDRESS"]."<br>".CITY.": ".$row["CITY"]."<br>".ZIP.": ".$row["ZIP"]."<br>".PHONE_NO.": ".$row["PHONE"]."<br>".EMAIL.": ".$row["EMAIL"]."<br> Extra informatie: ".$row["DETAIL"]."<br><br><center><a href='".$ROOT."map/".$advisorId.".gif'><img src='".$ROOT."map/".$advisorId.".gif' border='0' width='450' alt='De locatie van de adviseur'></a></center><br><br>";
    					$linkText		= "<a href=".$ROOT."verify.php?e=".urlencode($email)."&c=".$code.">".$ROOT."verify.php?e=".urlencode($email)."&c=".$code."</a><br><br>".YOUR_PROMOTIONAL_CODE_TO_GIVEAWAY." : ".$pCodeIssued."";
    				}
    				else
    				{
    					$advisorDetails = NO_ADVISOR_FOUND;
    					//$linkText		= YOUR_PROMOTIONAL_CODE_TO_GIVEAWAY." : ".$pCodeIssued."";
    				}
    
    				$body = getColumn("EMAIL_FORMATS", getColumn("LANGUAGE", $lang, "ID", "FOLDER"), "DEFAULT_FORMAT", "LANGUAGE_ID");
    				//$body = nl2br($body);
    				$body = str_replace("{NAME}", $fname ." ". $lname, $body);
    				$body = str_replace("{DETAIL}", $advisorDetails, $body);
    				$body = str_replace("{LINK}", $linkText, $body);
    				//echo $body; die;
    
    				sendMail($email, $WEBMASTER, SIGNUP_SUCCESSFUL, $body);
    				sendMail($WEBMASTER, $email, SIGNUP_SUCCESSFUL, $body);
    				
    				$bodyInfo = str_replace("{DETAIL}", $bodyInfo, NEW_MEMBER_DETAILS_EMAIL);
    				sendMail($WEBMASTER, $email, NEW_MEMBER_DETAILS_SUBJECT, $bodyInfo);
    
    Code (markup):

    SEMrush
     
    crazyhorse, May 7, 2005 IP
    SEMrush
  2. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would question your use of quotes on line 4
    '".substr($zip, 0, 3)."%'");
    PHP:
    You can always take your query and save it as a varible then echo it later to see if it is correct
    $test_display=("SELECT * FROM ".PREFIX."ADVISOR_ZIPCODE WHERE ZIPCODE LIKE '".substr($zip, 0, 3)."%'");
    ......
    .......
    .......
    echo $test_display;
    
    PHP:
     
    mushroom, May 7, 2005 IP
  3. crazyhorse

    crazyhorse Peon

    Messages:
    1,137
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Im no genious in PHP. Someonelse did this for me. Should i try and replace it and see whether it works.?
     
    crazyhorse, May 7, 2005 IP
  4. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The codeing confuses me also, and with out the whole thing to work with, I can't test any thing.
    so add new temporary before line 4.
     $test_display=("SELECT * FROM ".PREFIX."ADVISOR_ZIPCODE WHERE ZIPCODE LIKE '".substr($zip, 0, 3)."%'"); 
    PHP:
    then just before end of the page add another temporary line.
    echo $test_display; 
    PHP:
    run the script and post the display that that new line gives you.
     
    mushroom, May 7, 2005 IP
  5. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #5
    There has to be a var at the end of a printf to fill that %s which is saying expect a string. Look at the syntax on php.net.
     
    noppid, May 7, 2005 IP