An AMAZING COMPETITION!! - to fix the PDO

Discussion in 'General PHP' started by renlok, Jun 2, 2014.

  1. renlok

    renlok Administrator Staff Member

    Joined:
    Oct 20, 2008
    Messages:
    2,858
    Likes Received:
    330
    So me and jjjason84 tried for a while with no success to get this to work and so now it's your time to shine an opportunity you have all been waiting for! With the amazing chance to win absolutely nothing how can you say no?

    OK so you're probably wondering how can I win this great prize? Heres the deal:

    Over at
    https://github.com/renlok/WeBid/blob/master/adsearch.php
    the code between lines 166 and 179

    That means selecting more than one payment type will throw an error, can you believe it an error?!

    So your goal to win the ultimate prize is to fix it. Simples.
     
  2. Guest

    Guest Guest

    why not just ask for help ?
    competition there is not, sounds like you have been too long out in the sun :)

    dont think i can solve it but i give it a try ;)
     
    Last edited by a moderator: Aug 10, 2014
  3. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    Yea this error has been a pain trying to fix the payment types in the Advanced Search page.

    Renlok there is No Prize if they fix the problem?

    Ok if Renlok is not giving out a prize if the person fix's the payment types?

    Then i will give out a prize to the person that fix's this problem.
    I have been working on a updated webid version with tons of mods added to it and 11 themes for it. you can see more info about it here.

    Renlok knows about this webid script that i have been working on and he also has a copy of it.

    1 Lucky Winner will win the auction script that i have been working on if they fix the payment type problem in the Advanced Search page.
     
    Last edited: Jun 2, 2014
  4. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    I have come to declare the prize! Not leaving without it:D
    This has not been tested, but I am sure it will work.

    PHP:
    if (isset($_SESSION['advs']['payment']))
        {
            if (
    is_array($_SESSION['advs']['payment']) && count($_SESSION['advs']['payment']) > 1)
            {
                
    $pri false;
                foreach (
    $_SESSION['advs']['payment'] as $key => $val)
                {
                    if (!
    $pri)
                    {
                        
    $ora "((au.payment LIKE :payment{$val})";
                        
    $asparams[] = array(":payment{$val}"'%' $system->cleanvars($val) . '%''str');
                        
                    }
                    else
                    {
                        
    $ora .= " OR (au.payment LIKE :payment{$val})";
                        
    $asparams[] = array(":payment{$val}"'%' $system->cleanvars($val) . '%''str');
                    }
                    
    $pri true;
                }
                
    $ora .= ") AND ";
            }
            else
            {
                
    $ora "(au.payment LIKE :payment) AND ";
                
    //if above line does not work, disable it and enable the below line
                //$ora = "(au.payment LIKE :payment{$system->cleanvars($_SESSION['advs']['payment'][0]}) AND ";
                
    $asparams[] = array(':payment''%' $system->cleanvars($_SESSION['advs']['payment'][0]) . '%''str');
            }
        }
    Now where is my ultimate prize?
     
  5. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    Nope it is still not working correctly and when i pick like 3 Payment Choices with a correct and open auction info it will come back with this error ( No auction found ) but if i pick just 1 payment choice that is on the correct auction then it will display the auction.

    But you are getting closer on fixing this problem pani :)
     
  6. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Hi jjason84, if you remove the complete if statement for payment, does the adsearch work ok?
    How about this?
    PHP:
    if (isset($_SESSION['advs']['payment']))
        {
            if (
    is_array($_SESSION['advs']['payment']) && count($_SESSION['advs']['payment']) > 1)
            {
                
    $pri false;
                foreach (
    $_SESSION['advs']['payment'] as $key => $val)
                {
                    if (!
    $pri)
                    {
                        
                        
    $ora "((au.payment LIKE :payment)";
                        
    $asparams[] = array(":payment"'%' $system->cleanvars($val) . '%''str');
                        
                    }
                    else
                    {
                        
                        
    $ora .= " OR (au.payment LIKE :payment)";
                        
    $asparams[] = array(":payment"'%' $system->cleanvars($val) . '%''str');
                    }
                    
    $pri true;
                }
                
    $ora .= ") AND ";
            }
            else
            {
                
                
    $ora "(au.payment LIKE :payment) AND ";
                
    $asparams[] = array(':payment''%' $system->cleanvars($_SESSION['advs']['payment'][0]) . '%''str');
            }
        }
     
    Last edited: Jun 3, 2014
  7. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Or this one
    PHP:
    if (isset($_SESSION['advs']['payment'])) 
        { 
            if (
    is_array($_SESSION['advs']['payment']) && count($_SESSION['advs']['payment']) > 1
            { 
                
    $pri false
                foreach (
    $_SESSION['advs']['payment'] as $key => $val
                { 
                    if (!
    $pri
                    { 
                         
                        
    $ora "(au.payment LIKE :payment"
                        
    $asparams[] = array(':payment''%' $system->cleanvars($val) . '%''str'); 
                         
                    } 
                    else 
                    { 
                         
                        
    $ora .= " OR au.payment LIKE :payment"
                        
    $asparams[] = array(':payment''%' $system->cleanvars($val) . '%''str'); 
                    } 
                    
    $pri true
                } 
                
    $ora .= ") AND "
            } 
            else 
            { 
                 
                
    $ora "(au.payment LIKE :payment) AND "
                
    $asparams[] = array(':payment''%' $system->cleanvars($_SESSION['advs']['payment'][0]) . '%''str'); 
            } 
        }  
    This has got to be it. Don't have PDO setup to test, but this is the final solution. Got to be.
     
    Last edited: Jun 3, 2014
  8. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    No it don't work and i get a error saying something about this }
     
  9. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    Nope it don't work same problem as post #5 this error is a tricky bugger.
     
  10. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    And another to try
    PHP:
    if (isset($_SESSION['advs']['payment'])) 
        { 
            if (
    is_array($_SESSION['advs']['payment']) && count($_SESSION['advs']['payment']) > 1
            { 
                
    $pri false
                foreach (
    $_SESSION['advs']['payment'] as $key => $val
                { 
                    if (!
    $pri
                    { 
                         
                        
    $ora "(au.payment LIKE :payment$key"
                        
    $asparams[] = array(":payment$key"'%' $system->cleanvars($val) . '%''str'); 
                         
                    } 
                    else 
                    { 
                         
                        
    $ora .= " OR au.payment LIKE :payment$key"
                        
    $asparams[] = array(":payment$key"'%' $system->cleanvars($val) . '%''str'); 
                    } 
                    
    $pri true
                } 
                
    $ora .= ") AND "
            } 
            else 
            { 
                 
                
    $ora "(au.payment LIKE :payment) AND "
                
    $asparams[] = array(':payment''%' $system->cleanvars($_SESSION['advs']['payment'][0]) . '%''str'); 
            } 
        }
    I have been trying to add PDO in adsearch but it is not looking easy to test this
     
  11. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    Yea there is a lot of editing in the webid coding to get the pdo working in it. But that code did not work same problem as post #5 it seems it only wants to look for 1 payment choice.
     
  12. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    How about this one?
    PHP:
    if (isset($_SESSION['advs']['payment'])) 
        { 
            if (
    is_array($_SESSION['advs']['payment']) && count($_SESSION['advs']['payment']) > 1
            { 
                
    $pri false
                foreach (
    $_SESSION['advs']['payment'] as $key => $val
                { 
                    if (!
    $pri
                    { 
                         
                        
    $ora "((au.payment LIKE :payment$key)"
                        
    $asparams[] = array(":payment$key"'%' $system->cleanvars($val) . '%''str'); 
                         
                    } 
                    else 
                    { 
                         
                        
    $ora .= " OR (au.payment LIKE :payment$key)"
                        
    $asparams[] = array(":payment$key"'%' $system->cleanvars($val) . '%''str'); 
                    } 
                    
    $pri true
                } 
                
    $ora .= ") AND "
            } 
            else 
            { 
                 
                
    $ora "(au.payment LIKE :payment) AND "
                
    $asparams[] = array(':payment''%' $system->cleanvars($_SESSION['advs']['payment'][0]) . '%''str'); 
            } 
        }
     
  13. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    Nope same problem as post #5 trust me this problem will make you go nuts trying to find a fix for it. :p
     
  14. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    This is giving me good results (with partly added PDO on pre1.1.0 ) all parameters are passed in and the query looks ok and returns results

    PHP:
    if (isset($_SESSION['advs']['payment'])) 
        { 
            if (
    is_array($_SESSION['advs']['payment']) && count($_SESSION['advs']['payment']) > 1
            { 
                
    $pri false
                foreach (
    $_SESSION['advs']['payment'] as $key => $val
                { 
                    if (!
    $pri
                    { 
                         
                        
    $ora "(au.payment LIKE :payment"
                        
    $asparams[] = array(':payment''%' $system->cleanvars($val) . '%''str'); 
                         
                    } 
                    else 
                    { 
                         
                        
    $ora .= " OR au.payment LIKE :payment"
                        
    $asparams[] = array(':payment''%' $system->cleanvars($val) . '%''str'); 
                    } 
                    
    $pri true
                } 
                
    $ora .= ") AND "
            } 
            else 
            { 
                 
                
    $ora "(au.payment LIKE :payment) AND "
                
    $asparams[] = array(':payment''%' $system->cleanvars($_SESSION['advs']['payment'][0]) . '%''str'); 
            } 
        }
    HTML:
    SELECT count(*) AS total FROM webid_auctions au WHERE au.suspended = 0 AND (au.closed = '0') AND (au.payment LIKE :payment OR au.payment LIKE :payment OR au.payment LIKE :payment) AND au.starts <= :time ORDER BY :sort_by
    
    Array ( [0] => Array ( [0] => :payment [1] => %authnet% [2] => 2 ) [1] => Array ( [0] => :payment [1] => %worldpay% [2] => 2 ) [2] => Array ( [0] => :payment [1] => %moneybookers% [2] => 2 ) [3] => Array ( [0] => :sort_by [1] => au.ends ASC [2] => 2 ) [4] => Array ( [0] => :time [1] => 1401789738 [2] => 1 ) ) 
    
    Total found with PDO=1
    
    SELECT au.* FROM webid_auctions au WHERE au.suspended = 0 AND (au.closed = '0') AND (au.payment LIKE :payment OR au.payment LIKE :payment OR au.payment LIKE :payment) AND au.starts <= :time ORDER BY :sort_by LIMIT :offset, :perpage
    
    Array ( [0] => Array ( [0] => :payment [1] => %authnet% [2] => 2 ) [1] => Array ( [0] => :payment [1] => %worldpay% [2] => 2 ) [2] => Array ( [0] => :payment [1] => %moneybookers% [2] => 2 ) [3] => Array ( [0] => :sort_by [1] => au.ends ASC [2] => 2 ) [4] => Array ( [0] => :time [1] => 1401789738 [2] => 1 ) [5] => Array ( [0] => :offset [1] => 0 [2] => 1 ) [6] => Array ( [0] => :perpage [1] => 50 [2] => 1 ) ) 
    
    1
    and if i add payapal in the search

    HTML:
    SELECT count(*) AS total FROM webid_auctions au WHERE au.suspended = 0 AND (au.closed = '0') AND (au.payment LIKE :payment OR au.payment LIKE :payment OR au.payment LIKE :payment OR au.payment LIKE :payment) AND au.starts <= :time ORDER BY :sort_by
    
    Array ( [0] => Array ( [0] => :payment [1] => %paypal% [2] => 2 ) [1] => Array ( [0] => :payment [1] => %authnet% [2] => 2 ) [2] => Array ( [0] => :payment [1] => %worldpay% [2] => 2 ) [3] => Array ( [0] => :payment [1] => %moneybookers% [2] => 2 ) [4] => Array ( [0] => :sort_by [1] => au.ends ASC [2] => 2 ) [5] => Array ( [0] => :time [1] => 1401790203 [2] => 1 ) )
     
    Total found with PDO=1352
    
    SELECT au.* FROM webid_auctions au WHERE au.suspended = 0 AND (au.closed = '0') AND (au.payment LIKE :payment OR au.payment LIKE :payment OR au.payment LIKE :payment OR au.payment LIKE :payment) AND au.starts <= :time ORDER BY :sort_by LIMIT :offset, :perpage
    
    Array ( [0] => Array ( [0] => :payment [1] => %paypal% [2] => 2 ) [1] => Array ( [0] => :payment [1] => %authnet% [2] => 2 ) [2] => Array ( [0] => :payment [1] => %worldpay% [2] => 2 ) [3] => Array ( [0] => :payment [1] => %moneybookers% [2] => 2 ) [4] => Array ( [0] => :sort_by [1] => au.ends ASC [2] => 2 ) [5] => Array ( [0] => :time [1] => 1401790203 [2] => 1 ) [6] => Array ( [0] => :offset [1] => 0 [2] => 1 ) [7] => Array ( [0] => :perpage [1] => 50 [2] => 1 ) ) 50
    I have not used browse.php instead I have entered the $db->query($query, $params); in the adsearch.php
     
    Last edited: Jun 3, 2014
  15. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    Ok you gotten a lot closer now :) i can pick more than 1 Payment Choice and if 1 is the correct payment on the auctions it displays the auction but there still one little problem with it i have PayPal and Cheque as a payment on a auction and if i pick Cheque and not paypal it comes back with this error ( No auction found ) but if i only pick Cheque then the auction will be displayed

    I take it you really want the prize pani :p
     
    Last edited: Jun 3, 2014
  16. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Maybe because it is searching for Array ( [0] => :payment [1] => %Cheque% [2] => 2 ) when it should be searching for payment method 1.
    In auction table in database my payment column has this (all payments selected for auction) = paypal, authnet, worldpay, moneybookers, toocheckout, 0, 1, 2
    So instead of cheque we should be searching for payments like %1%.And that will be coming from the search form.

    In adsearch.php
    find

    PHP:
    $payment_options unserialize($system->SETTINGS['payment_options']);
    foreach (
    $payment_options as $k => $v)
    {
        
    $checked = (in_array($k$payment)) ? 'checked' '';
        
    $payment_methods .= '<p><input type="checkbox" name="payment[]" value="' $v '" ' $checked '>' $v '</p>';
    }
    and change to

    PHP:
    $payment_options unserialize($system->SETTINGS['payment_options']);
    foreach (
    $payment_options as $k => $v)
    {
        
    $checked = (in_array($k$payment)) ? 'checked' '';
        
    $payment_methods .= '<p><input type="checkbox" name="payment[]" value="' $k '" ' $checked '>' $v '</p>';
    }
     
    Last edited: Jun 3, 2014
  17. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    nope still got the same problem as post #15
     
  18. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    try changing the above to
    PHP:
    $payment_options unserialize($system->SETTINGS['payment_options']);
    foreach (
    $payment_options as $k => $v)
    {
        
    $checked = (array_key_exists($karray_flip($payment))) ? 'checked' '';
        
    $payment_methods .= '<p><input type="checkbox" name="payment[]" value="' $k '" ' $checked '>' $v '</p>';
    }  
    This is for bank transfer being selected if a payment option AND at least one payment method selected. Don't know if you where getting this.

    In your payment select tick boxes can you tell me what value the cheque, cash and bank tranfer is
    It should be

    HTML:
    <tr>
    <td align="center"><input type="checkbox" name="payment[]" value="toocheckout"><br>2Checkout</td>
    <td align="center"><input type="checkbox" name="payment[]" value="0"><br>Bank Transfer</td>
    <td align="center"><input type="checkbox" name="payment[]" value="1" checked=""><br>Cheque</td>
    <td align="center"><input type="checkbox" name="payment[]" value="2"><br>Cash on Delivery</td>
    </tr>
    be back tonight on this, got to shoot off, late as always.
     
    Last edited: Jun 3, 2014
    renlok likes this.
  19. jjjason84

    jjjason84 Donor Donor

    Joined:
    Jun 26, 2012
    Messages:
    702
    Likes Received:
    61
    The Bank transfers are built in the gateways just like paypal but here is my coding that displays the payments

    PHP:
    // payments
    $payment_methods '';
    $query "SELECT * FROM " $DBPrefix "gateways LIMIT 1";
    $db->direct_query($query);
    $gateways_data $db->result();
    $gateway_list explode(','$gateways_data['gateways']);
    foreach (
    $gateway_list as $v)
    {
        if (
    $gateways_data[$v '_active'] == 1)
        {
            
    $checked = (in_array($v$payment)) ? 'checked' '';
            
    $payment_methods .= '<p><input type="checkbox" name="payment[]" value="' $v '" ' $checked '>' $system->SETTINGS['gatways'][$v] . '</p>';
        }
    }

    $payment_options unserialize($system->SETTINGS['payment_options']); 
    foreach (
    $payment_options as $k => $v

        
    $checked = (array_key_exists($karray_flip($payment))) ? 'checked' ''
        
    $payment_methods .= '<p><input type="checkbox" name="payment[]" value="' $k '" ' $checked '>' $v '</p>'
    }
     
  20. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Hi jjason84, that looks good. The payment gateways are slightly different to the payment options.
    If you enable in an auction all the payments you have what does the database->auctions table-> payments column have inside it for that auction?

    Can you go to the includes/class_db_handle.php and enable line 172 and 173
    PHP:
    (//print_r("params" . $query);
            //print_r($params);
    )
    Then show me what the result is from your adsearch with the options you say are not working correctly.
     

Share This Page