Jump to content

fritz.fx

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Posts posted by fritz.fx

  1. I'm getting nothing out of your query. (sorry, I get a bit slow without sleep) 

    1) Why would you expect to get a different count for killers than for deaths? Can you have a killer without a death? or a death without a killer? 

    I expect different results this way. eg: george kills fred 5 times .... fred kills george 15 times. result should be

    george == 5 == 15

    fred ==15 ==5

     

    haven't tried out your country query yet but it looks like it's exactly what I'm looking for.

  2. Hey guys.

    I haven't done any PHP for a while and my memory isn't so good  :shrug:

    I'm trying to do a count from 2 columns in one table from an array of names.

    Table setup:

    sqltable.png

     

    this is what I have:

    $names = array('Losos', '.minion', 'STAVY', 'brothrsinarms', '.-(AUST)-.Fatal', 'Vergetta');
    foreach ($names as $names) {
    $result = mysql_query("SELECT *, count(killer) as kills, count(victim) as deaths FROM tbl_killlog where killer = '$names'");
       
    while($row = mysql_fetch_array($result))
    {
      $name = $row['killer'];
      $kills = $row['kills'];
      $deaths = $row['deaths'];
      echo "$name == $kills == $deaths<br>";
      }
    }

     

    So, what I want, is for each $name get the number of "kills" (killer) AND the number of "deaths" (victim) but for some reason I'm getting the same result from both.

    Anybody got any ideas??

     

    Oh, also, just one more query, Another table I have is a log of names/countries. what would  the query be for counting individual country names.. eg " ireland = 5, Germany = 15 etc etc  ??

    table pic:

    sqltable2.png

     

    Cheers

    Fritz

     

  3. Hi all, I've been stuck on this little problem for a while.

    I have a form for recurring payments pointing to Paypal where people can select an amount, an interval (1,2,3, & so on) then a duration (weeks, months, years) then submit it. After all the jazz on Paypals site, they are redirected to a "thankyou page" where I insert the relevant data into a DB.

    My problem is, Paypal returns (to the thankyou page) everything except the interval and duration.

    How can I get Javascript to save those two on submit so I can use PHP to retrieve them after the Paypal page??

     

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="business" value="<?php echo $paypal_email; ?>" />
    <input type="hidden" name="cmd" value="_xclick-subscriptions"> 
    <input type="hidden" name="return" value="http://www.the thankyou page.php" />
    <input type="hidden" name="item_name" value="the item name"> 
    <input type="hidden" name="currency_code" value="AUD"> 
    <br /><input name="custom" type="text" class="donate_box_name" value="<?php echo $username; ?>" size="21" maxlength="40" /><br />
    Donation amount<br /> 
    <select name="a3" class="donate_box_amount">
                    <option>$5.00</option>
                    <option>$10.00</option>
                    <option>$15.00</option>
                    <option>$20.00</option>
                    <option>$25.00</option>
                    <option>$30.00</option>
                    <option>$40.00</option>
                    <option>$50.00</option>
                    <option>$75.00</option>
                    <option>$100.00</option>
                    <option>$125.00</option>
                    <option>$150.00</option>
                    <option>$175.00</option>
    </select><br />
    Donation duration<br /> 
    <select name="Duration"> 
    <option value="5">1</option> 
    <option value="5">2</option> 
    <option value="5">3</option> 
    <option value="5">4</option>
    <option value="5">5</option> 
    <option value="5">6</option>  
    </select> <br /> 
    
    <select name="Interval"> 
    <option value="W" selected="selected">Weeks</option>
    <option value="M">Months</option>
    <option value="Y">Years</option>
    </select><br /> 
    <input type="image" src="btn_donate_LG.gif" name="submit" >
    </form

     

    I've tried a few things, but none of them are "just right"

    (One saves all the form fields to a cookie, bit it exceeds the max cookie length and I don't actually get the info I need.  Another works just fine, but it saves the fields into a seperate cookie for each. (All in one would be better))..

     

    Any help would be appreciated. I'm on the home stretch with this project and this problem has slowed me down a fair bit.

  4. Is there any way to read the header info from a .PNG file similar to the way exif_read_data gets the info from TIFF & JPEG files??

     

    I get this error

    Warning: exif_read_data(pb025900.tiff) [function.exif-read-data]: File not supported in C:\xampp\htdocs\take5\svsstest\pbucon\png.php on line 5

    pb025900.png:

    When using this code

    $exif = exif_read_data('pb025900.png', 0, true);
    echo "pb025900.png:<br />\n";
    foreach ($exif as $key => $section) {
        foreach ($section as $name => $val) {
            echo "$key.$name: $val<br />\n";
        }
    }
    

  5. OK with a little help from another forum (sorry, don't shoot me)

    I've resolved my filesize problem by making it simpler to sort out, it is:  (find .png files smaller than 50kb and NOT copying the 2kb *other* files from the remote FTP server  (which weren't needed after all))

    $count = 0;
    foreach(glob('*.png') as $file)
        if(filesize($file) < (50 * 1024))
            $count++;
    echo $count

     

    From that I've added my own little twist:  (including a TOTAL count of .png files)  (this is what I have currently, obviously needs a cleanup)

    $total_jpg_file=count(glob("*.png"));
    echo "Number of screenshots currently hosted = ".$total_jpg_file;
    
    //The next 4 lines count the number of screenshots (.png) that are currently hosted LOCALLY
    $count = 0;
    foreach(glob('*.png') as $file)
        if(filesize($file) < (50 * 1024))
            $count++;
    // The line below converts that count (above) into a percentage and assigns a variable to it ($pc)
    $pc = floor ($count / $total_jpg_file * 100);
    echo ' <br />';
    
    //This next section checks the above percentage of black screenshots(variable $pc) and then does some cool shit to it before it displays it to the screen.
    // if there is more than 50% of black screenies it will display it as RED and BLINKING text  (taking into account the CSS or style type)
       echo "Number of Black Screenshots = ".$count;
      // echo $count   ;
       echo " <blink><span class=\"style2\"> (";
       echo  $pc;
       echo "%)";
    echo "</span></blink>";
    echo ' <br />';
    //............if the percentage is between 25 and 50% it will display it as orange text.  (taking into account the CSS or style type)
    } elseif($pc >= 25) {
        echo "Number of Black Screenshots =  ";
       echo $count   ;
       echo "<span class=\"style3\">(";
       echo  $pc;
       echo "%)";
    echo "</span>";
    echo ' <br />';
    //if the percentage is between 1 and 25% it will display it as green text.  (taking into account the CSS or style type)
    } elseif ($pc >= 1) {
       echo "Number of Black Screenshots = ";
       echo $count   ;
       echo "<span class=\"style4\"> (";
       echo  $pc;
       echo "%)";
    echo "</span>";
    echo ' <br />';
    } else {
    //If shit happens then it will display the below message.
        echo "Unable to determine number of Black screenshots at this time";
    }

     

     

    As for this little bit your concerned about Ignace

    $goforit = ftp_get($conn_id, $file, $file, FTP_BINARY);

     

    NO, I'm NOT sure that it is correct at all (Still a PHP newbie)  BUT, It does do exactly what I want it to do, so out of fear of screwing up a script that currently works, I'm leaving it alone.

    (your remote file is the same as your local file?) my remote file overwrites my local file of the same name)

    Oh by the way

    oh didn't know you were using zero-indexing Smiley the problem would be that $username is empty at the moment you perform your query or do you include something before your create the db connection?

    I did realise this while I was at work, and thought to myself " you idiot!!" turns out that that was the problem. moved the command down a few lines after declaring the $username and it worked.  thanks

     

    Thanks for your time

    My hair-pulling is over for the time being..

    Problem resolved.

    Cheers

  6. I've worked out the first problem, by creating a new column named "ID4" and giving it a value of "ID" then used this code :

    $previous = mysql_query("SELECT username FROM last_check WHERE ID4 = 'ID'");  
    $row = mysql_fetch_array($previous);
    $previous_user = $row['username'];
    //Update DB with the new username
    mysql_query("UPDATE last_check SET username = '$username' WHERE username = '$previous_user'");

     

    As for the second problem, I might have to work out how just count the number of files on the local server that are greater than but less than a certain size.

  7. Thanks ignace but I've tried that

    Not too worried about SQL injection, as only registered users would be using the script, and that is restricted to only a group of users that I know  (http://www.phpfreaks.com/forums/index.php/topic,207458.0.html)

    my .htaccess file does the rest.

     

    here is the full code (including your suggestion (line 4))

    query 2 problem is after "//Download files"

     

    // Connect to  Database
    mysql_connect("localhost", "DB username", "DB password") or die(mysql_error());
    mysql_select_db("DB name") or die(mysql_error());
    //insert into DB the last member who checked screenies
    mysql_query("UPDATE last_check SET username = '$username'");
    //mysql_query($query) or die('Error, query failed');
    set_time_limit(0);
    include_once("config.php");
    error_reporting(E_ALL);
    
    echo "Update process<br>";
    
    
    // Connection
    $conn_id = ftp_connect($ftp_server);
    
    // Login with Username and Passwort
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    ftp_pasv($conn_id, true);
    // Connectivity
    if ((!$conn_id) || (!$login_result)) {
            echo "FTP connection has failed!<br>";
            echo "connection to $ftp_server with Username $ftp_user_name trying.<br>";
            exit;
        } else {
           echo "connecting to server \n<br>";
        }
        // Ins directory
        if (ftp_chdir($conn_id, $dir)) {
       // echo "Current Directory: " . ftp_pwd($conn_id) . "\n<br>";
    } else {
        echo "Directory exchange failed.\n<br>";
    }
    
        
    
    // Read the folder
    while ($nlist = ftp_nlist($conn_id, "./pb0*.*")) {
    foreach ($nlist as $file)
    {
    
    
    //Download files
    $goforit = ftp_get($conn_id, $file, $file, FTP_BINARY);
    
    if (!$goforit) {
    echo "$file could not be loaded!<br>";
    } else {
    echo "$file has been successfully updated!<br>";
    }
    if (ftp_size($conn_id, "./pb0*.png") < 20480)
    {
    echo "$file was a black Screenshot (this is experimental atm)<br>";
    }
    
    //Deleting files from the source
    if ($file == "pbsvss.htm") {
    } else {
    $delete = ftp_delete  ($conn_id, $file);
    }
    if (!$delete)  {
    echo "$file was not deleted!<br>";
    } else {
    //echo "$file has been successfully removed!<br>";
    }
    }
    }
    
    $download1 = ftp_get($conn_id, "pbsvss.htm", "pbsvss.htm", FTP_BINARY);
    if (!$download1) {
    echo "pbsvss.htm could not be loaded!<br>";
    } else {
    echo "<strong>Screenshots have been successfully updated!</strong><br>";
    //echo "Pbsvss.htm file has been successfully downloaded!<br>";
    }
    //close
    ftp_close($conn_id);
    
    echo "Update Completed<br>";
    $filename = "pbsvss.htm";
    $file = fopen($filename, "r");
    $filesize = filesize($filename);
    $text = fread($file, $filesize);
    fclose($file);
    $text = str_replace(".htm",'.png', $text);
    echo($text);

  8. I hate asking questions, I prefer to figure it out by myself, but the ol' age thing gets in the way now, so after a few hours of hair pulling, I come back here.

     

    first query

    This one should be simple, I just can't see it...

    I have a table named "last_check" and a column named "username"

    I have a script which, once a $username clicks a submit button which 'includes' another script.. within that 'included' script I'm trying to write the command to update that users $username into "username on the table "last check"

    I have this:

    mysql_query("UPDATE last_check SET username = $username");

    which isn't working.

     

    Basically as an example >>  If Fred clicks submit then update "username" on "last_check" to Fred.  Then, if Mary then clicks the submit button >> overwrite Fred with Mary !!

     

    Second query

    My script connects to an FTP server and copies files from that server to another and checks the size while it's at it, if the filesize is under a certain size it echo's a message, which works, only problem is, it copies two different files.  a *.png and a .htm.

    How can I set it so that if the filesize is greater than the .htm (lets say 20480bytes) but less than the .png (lets say 50000bytes)??

    This is what I have so far, but only detects the "less than" part of it all.

    $goforit = ftp_get($conn_id, $file, $file, FTP_BINARY);
    if (!$download) {
    echo "$file could not be loaded!<br>";
    } else {
    echo "$file has been successfully updated!<br>";
    }
    if (ftp_size($conn_id, "./pb0*.png") < 20480)
    {
    echo "$file was a black Screenshot (this is experimental atm)<br>";

     

  9. ^^

    Thanks Wildteen88, but that didn't work for me.

    I've ended up using ProjectFears code >

    $names = explode("||", file_get_contents("names.txt")); //put each name into an array
    if(in_array($_POST['username'],$names)){
    die("Name is a clan member name!");
    }else{
    //its all good!
    }

    And arranging my names.txt file to look like this:

    ||name1||

    ||name2||

    ||and so on||

     

    Works fine, problem solved.

    Thanks

  10. Thanks again

    might give your second example tomorrow (when I'm a little more sober :)  )

     

    But just out of curiousness could I arrange my 'names.txt' file so that every name is on a new line and change the script so that it looks like this>

    names = explode("\rn", file_get_contents("names.txt")); //put each name into an array
    
    if(in_array($_POST['username'],$names)){
    die("Name is a clan member name!");
    }else{
    //its all good!
    }

    "explode("\rn""      is for a new line???

    I'm still a PHP newbie but \rn is a new line isn't it??

     

    Just curious here!!

  11. Hey guys

    I've written a standard php-mysql driven 'members' script to allow "registered" members access to certain parts of my site, which works like a charm, only thing I'd like to restrict registration to usernames already approved'

    So far I've managed to do it by putting this in the script >

    //if the name does not exist it gives an error
    if ($check2 != 0) {
    die('Sorry, the username '.$_POST['username'].' is already in use.');
    }
    //if username equals a clan member
    if($_POST['username'] == 'A Clan members name I have to manually insert into the script here') {
    }
    else {
         die ('The username you have submitted does not have the permissions to access this resource....} 
    //carry on if that name == A Clan members name

    Only problem with this way I have to do it 50 times for each clan member, which is pretty messy as you could imagine. So to get around the messy part I have the names of those names allowed in a text file (one per line) and am trying to get the script to check the name submitted in the registration form against a name in the text file.

    So far I have this >

    //if the name exists it gives an error
    if ($check2 != 0) {
    die('Sorry, the username '.$_POST['username'].' is already in use.');
    }
    //if username equals a clan member
    $lines = file('names.txt');
    foreach ($lines as $line_num) => $line)
    if($_POST['username'] == $line) {
    }
    else {
         die ('The username you have submitted does not have the permissions to access this resource....} 
    //carry on if that name == A Clan members name

     

    My problem is, is that it's refusing access to any name, whether on the list or not. Can anybody see where I'm going 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.