Jump to content

mrdamien

Members
  • Posts

    186
  • Joined

  • Last visited

Posts posted by mrdamien

  1. Not a PHP problem.

     

    Try changing your css:

     

    From this:

    <style type="text/css">
    .progressbar {
    border: #333333 1px solid;
    height: 2px;
    margin: 0 2px;
    padding: 1px;
    width: 72px;
    }
    .bar {
    background-color: #ff7700;
    height: 2px;
    float: left;
    }
    </style>

     

    to this:

     

    <style type="text/css">
    .progressbar {
    border: #333333 1px solid;
    height: 2px;
    margin: 0 2px;
    font-size: 0px;
    padding: 1px;
    width: 72px;
    }
    .bar {
    background-color: #ff7700;
    height: 2px;
    line-height: 2px;
    font-size: 0px;
    float: left;
    
    }
    </style>

  2. The starting number would be:

     max($this->currentPage-5, 0);

    The ending page number would be:

    min($this->currentPage+5, $this->totalPages)
    

    so you can change your loop:

     

    $start =  max($this->currentPage-5, 0);
    $end = min($this->currentPage+5, $this->totalPages);
    for ($i=$min; $i < $max; $i++) {
    if($i != $this->currentPage) {
    	...
    }else{
    	...
    }
    }

  3. If you have multiple number-signs in the url, then all but the last segment following the number sign, would be part of the GET variables ( I think ).

     

    As far as I know, that is controlled by the web-server (i.e. apache). But I've never heard of apache having this problem... What web server are you using ?

  4. Edit: Since I'm not that great with regular expressions, and don't want to spend very long testing... heres a less-regex idea.

     

    Untested:

    preg_match( '/([.]{1,255}@([.]{1,255})/', $text, $matches);
    
    foreach($matches as $match)
    {
         if(filter_var($match, FILTER_VALIDATE_EMAIL)){
              $text = str_replace($match, "<a href=\"mailto:$match\">$match</a>", $text);
         }else{
              $text = str_replace($match, @<a href=\"http://twitter.com/$match\" target=\"_blank\">$match</a>", $text);
         }
    }
    

    Find all strings resembling "@(characters)".

    Use PHPs function to determine if its an email.

    If not an email, its a twitter account.

     

    I don't know if twitter has username restrictions (Like not symbols) if so, you'll probably want to test for those again, in the else clause.

  5. mysql_num_rows wants the result-resource as a paramater, not the query :P

     

    Therefore:

    $result=mysql_query($sql);
    
    if(mysql_num_rows($result) > 0){ // <- change $sql to $result.
       $sql = "DELETE FROM horsedata WHERE id = '".(int)$horseid."'"; // (int) for safety
       $result=mysql_query($sql);
            echo "You have Euthanized this horse.";
       }
    

     

  6. Your script works for me. Minus the 2 missing curly-braces, your script works.

     

    What version of PHP/GD are you using?

    <?php
    $file = 'test.jpg';
    
    // Get the dimensions
    list($width, $height) = getimagesize($file);
    
    // Define our source image
    $source = imagecreatefromjpeg($file);
    
    // Creating the Canvas
    $bwimage= imagecreate($width, $height);
    
    //Create our 2 colours
    
    $white = imagecolorallocate($bwimage, 255, 255, 255);
    $black = imagecolorallocate($bwimage, 0, 0, 0);
    
    //Reads the origonal colors pixel by pixel
    for ($y=0;$y<$height;$y++)
    {
    for ($x=0;$x<$width;$x++)
    {
    $rgb = imagecolorat($source,$x,$y);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >>  & 0xFF;
    $b = $rgb & 0xFF;
    
    //if red is 255 and green is over 197 then colour in black, else colour in white
    if($r=255 and $g>197)
    {
    imagesetpixel($bwimage,$x,$y,$black);
    }
    else
    {
    imagesetpixel($bwimage,$x,$y,$white);
    }
    
    } // This was missing
    } // This was missing
    ?>
    

     

  7. Exceptions are difficult to know when to use.

     

    Both of your examples are not good examples of where to use exceptions.

     

    For form validation, either the form is valid, or it isn't. If it isn't you should simply show the form again, and ask that it be properly filled.

    For SQL queries, again, either the query is valid, or it isn't. All the queries you place in your site should be valid 100% of the time, so there is little need to validate them again.

     

    Exceptions should more-or-less be used when the script cannot continue past a point, because some external mechanism is not working.

     

    This is just my opinion of course.

     

    You could of course use exceptions for form-validation, but they won't add any functionality compared to

    <?
    if(!isset($_POST['email'])){
    $error_message .= "An email is required";
    }
    ?>
    

  8. $totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid='$compare' OR challgdid='$compare'"); // $compare is still an array at this point

     

    so,

     

    $compare=mysql_query("SELECT teamid FROM membersteam WHERE memberid='{$_COOKIE['user']}'");
    $compare=mysql_fetch_array($compare);
    $compare=$compare[0]; // now $compare is the teamid field
    
    $totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid='$compare' OR challgdid='$compare'");
    $totalchall=mysql_fetch_array($totalchall);
    $totalchall=$totalchall[0];

  9. <?php
    //Organization Name
    $mail_from="$organization";
    //Organization Telephone
    $message.="$organization_phone";
    //Organization Mail
    $message.="$organization_mail";
    //General Inquiries
    $message.="$general_inquires";
    // From
    $header="From: $organization <$mail_from>\n".
    "Content-type: text/html";
    // Enter your email address
    $to ='dealers@countrydelights.ca';
    // Variables
    $message.=$var1.'<p>organization phone number</p><br>'.$var2.'<p>organization email</p><br>'.$var3.'<p>general inquiries</p><br>';
    // Send Form
    $send_contact=mail($to,$subject,$message,$header);
    // Check, if message sent to your email
    // display message "We've recived your information"
    if($send_contact){
    echo "We've recived your contact information";
    }
    else {
    echo "ERROR";
    }
    ?>
    

    You gotta specify Content-type in the headers.

  10. while ($row = mysql_fetch_array($result)) {
    $start = $row["start"];
    $end = $row["end"];
    $date = $row["date"];
    if($previous_date === 0){
          $previous_date = $date;
    }else if($date != $previous_date){
          include ("header.php");
    }
    
    echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='4'><TR>
          <TD WIDTH='25%' NOWRAP>$date</TD>
          <TD WIDTH='20%'>$start</TD>
          <TD WIDTH='15%'>$end</TD>
          </TR></TABLE>";
    if($date != $previous_date){
          $previous_date = $date;
          include ("footer.php");
    }
    
    }
    

    I think this is what you want...

  11. $sql = "SELECT * from XXX where start_search BETWEEN '$nowq_date' AND '$nowq5_date' ORDER BY start_search ASC";
    $result = mysql_query($sql,$connection) or die("Invalid query: " . mysql_error());
    $previous_date = 0;
    while ($row = mysql_fetch_array($result)) {
    $start = $row["start"];
    $end = $row["end"];
    $date = $row["date"];
    if($previous_date === 0){
          $previous_date = $date;
    }else if($date != $previous_date){
          $previous_date = $date;
          echo "<br>"; // extra space
    }
    
    
    echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='4'><TR>
          <TD WIDTH='25%' NOWRAP>$date</TD>
          <TD WIDTH='20%'>$start</TD>
          <TD WIDTH='15%'>$end</TD>
          </TR></TABLE>";
    }
    

     

  12. like what does this mean? why are they equaled to each other then to an array?

    $images = $prices = $titles = array();
    

    This is just to initialize variables.

    It could also be done like this:

    $images = array();
    $prices = array();
    $titles = array();
    

    or not at all.

     

    why did you put [] after the variables $image,$prices,$title?

     

    $images[] = "<td>test1</td>";
    $prices[] = "<td>test2</td>";
    $titles[] = "<td>test3</td>";
    

     

    $array[] = is equivalent to array_push.

     

     

    last question is...what is implode doing?

     

    Implode takes an array, and gives you a string of all the values, seperated by the first paramaters value.

    EX:

    Implode array(1,2,3) with '#' gives "1#2#3"

     

  13. include "db.php";
    
    $query = mysql_query("SELECT price, title FROM listings") or die(mysql_error());
    
    $images = $prices = $titles = array();
    while($fetch = mysql_fetch_array($query))
    {
    $images[] = "<td>test1</td>";
    $prices[] = "<td>test2</td>";
    $titles[] = "<td>test3</td>";
    }
    
    
    echo "<table>";
    
    echo "<tr>"
    . implode("", $images)
    . "</tr>";
    
    echo "<tr>"
    . implode("", $prices)
    . "</tr>";
    
    echo "<tr>"
    . implode("", $titles)
    . "</tr>";
    
    echo "</table>";
    
    

     

  14. <?php
    function get($url){
    $context = stream_context_create(
    	array(
    		'http' => array(
    			'method'=>"GET"
    		)
    	)
    );
    return file_get_contents($url, null, $context);
    }
    
    $page = get('http://www.nws.noaa.gov/view/validProds.php?prod=SVR&node=KBUF');
    
    // Strip stuff before <pre> 
    $page = substr($page, strpos($page, "<pre>") + 5);
    // and after $$
    $page = substr($page, 0, strpos($page, "$$"));
    
    // At this point, $page is equal to everything inbetween the <pre> tags
    
    // Find the date like: 1028 AM EST MON DEC 15 2008
    $success = preg_match('([0-9]{3,4} [A-Z]{2} [A-Z]{3,4} [A-Z]{3} [A-Z]{3} [0-9]{1,2} [0-9]{4})', $page, $matches);
    
    if($success){
    $page = substr($page, strpos($page, $matches[0]) + strlen($matches[0]));	
    }
    
    echo $page;
    
    ?>

     

    For me this gave:

     

    THE NATIONAL WEATHER SERVICE IN BUFFALO HAS ISSUED A

     

    * SEVERE THUNDERSTORM WARNING FOR...

      NORTHWESTERN CATTARAUGUS COUNTY IN WESTERN NEW YORK

      NORTHERN CHAUTAUQUA COUNTY IN WESTERN NEW YORK

      ERIE COUNTY IN WESTERN NEW YORK

     

    * UNTIL 1130 AM EST

     

    * AT 1022 AM EST...NATIONAL WEATHER SERVICE DOPPLER RADAR INDICATED A

      LINE OF SHOWERS AND EMBEDDED THUNDERSTORMS CAPABLE OF PRODUCING

      DAMAGING WINDS IN EXCESS OF 60 MPH.  THESE STORMS WERE LOCATED

      ALONG A LINE EXTENDING FROM 10 MILES EAST OF PORT COLBORNE TO 5

      MILES SOUTHWEST OF FREDONIA...AND MOVING EAST AT 50 MPH.

     

    * SEVERE THUNDERSTORMS WILL BE NEAR...

      BUFFALO...KENMORE AND SILVER CREEK BY 1035 AM EST...

      SLOAN...DERBY AND ATHOL SPRINGS BY 1040 AM EST...

      CHEEKTOWAGA...DEPEW AND WILLIAMSVILLE BY 1045 AM EST...

      HARRIS HILL BY 1050 AM EST...

     

    THESE ARE DANGEROUS LINE OF SHOWERS. VERY LITTLE LIGHTNING IS

    OCCURRING WITH THIS LINE OF SHOWERS. DO NOT WAIT FOR THE SOUND OF

    THUNDER TO SEEK SHELTER. PEOPLE OUTSIDE SHOULD MOVE TO A

    SHELTER...PREFERABLY INSIDE A STRONG BUILDING BUT AWAY FROM WINDOWS.

     

    LAT...LON 4250 7936 4257 7916 4271 7905 4276 7891

          4279 7887 4295 7891 4310 7850 4309 7847

          4252 7847 4229 7966

    TIME...MOT...LOC 1526Z 257DEG 39KT 4285 7900 4241 7936

     

    If they ever drastically change the page though, it would need to be modified.

  15. I open them with the Preview/Debug in browser inside Dreamweaver 8.  Also please note that I'm have not installed any thing like WAMP or XAMPP.

     

    Is that the problem? 

    Yes that is the problem. PHP files need to be parsed, otherwise your page will show your source code.
  16. <?php
    if(get_magic_quotes_gpc())
    {
    //clean XSS/SQL injection
    function clean_post(&$var) {
    
    $var=strip_tags(trim(mysqli_real_escape_string($var)));
    $var=htmlspecialchars($var,ENT_QUOTES);
    }
    
    array_walk_recursive($_POST,'clean_post');
    } 
    ?>

    Also, make sure get_magic_quotes_gpc() is not returning false.

  17. <?php
    if ($_POST['Submit']=='Buy this badge'){
    if ($_SESSION['Money'] >= 15)&& $_SESSION['badge1'] = 0){
         $sql = "UPDATE users SET "$_SESSION['Money']" = "$_SESSION['Money']" - 15 AND UPDATE users SET "$_SESSION['badge1']" = 1";
     $result = mysql_query($sql) or die (mysql_error()); 
     echo "<h3>You have received your badge!</h3><br><a href=myaccount.php>Click here to go to your account</a>";
    } else {
    echo "<h3>You either own this badge or do not have enough ARO$.</h3><br><p>Please click the back button to go back a page.</p>"; }
    }
    ?> 
    

    UPDATE users SET ".$_SESSION['Money']." = "$_SESSION['Money']...

    should probably be UPDATE users SET money = ".$_SESSION['Money']...

     

    $_SESSION['badge1'] should be equal to the field for badge1 I'm guessing.

     

    Since your current code makes the query eval to "SET 0 = 1" which is wrong.

×
×
  • 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.