PHP/SQL help

Discussion in 'Web Design & Coding' started by ziptrx, Jul 10, 2010.

  1. ziptrx

    ziptrx OSNN Addict

    Messages:
    53
    Code:
    if($_GET['do']=="pendingoffers")
        {
            print"<table width=90%><tr><th colspan=3>Pending Offers</th></tr><tr><th width=20%>User</th><th width=30%>Offer</th><th width=50% nowrap>Action</th></tr>";
            $getpending=mysql_query("select * from pending where denied=0",$c);
    
                if(mysql_num_rows($getpending)==0)
                    {
                        print"<tr><td colspan=3>No offers are currently pending review</td></tr>";
                    }
                while($p=mysql_fetch_array($getpending))
                    {
                        $getuserinfo=mysql_query("select * from users where id={$p['user_id']}",$c);
                        $us=mysql_fetch_array($getuserinfo);
                        $getofferinfo=mysql_query("select * from offers where id={$p['offer_id']}",$c);
                        $off=mysql_fetch_array($getofferinfo);
                        print"
                            <tr>
                                <td><a href=\"panel.php?do=finduser&user={$us['username']}\">{$us['username']}[{$us['id']}]</a></td>
                                <td>{$off['name']}</td>
                                <td nowrap>
                                    <form action=panel.php method=get>
                                        <input type=hidden name=do value=pendingoffers>
                                        <input type=hidden name=approve value=1>
                                        <input type=hidden name=pending value=\"{$p['id']}\">
                                        <input type=submit class=button value=Approve>
                                    </form>
                                    <form action=panel.php method=get>
                                        <input type=hidden name=do value=pendingoffers>
                                        <input type=hidden name=deny value=1>
                                        <input type=hidden name=pending value=\"{$p['id']}\">
                                        <input type=submit class=button value=Deny>
                                    </form>
                                </td>
                            </tr>
                        ";
                    }
                print"</table>";
    
    if($_GET['approve'])
        {
            $getpendinfo=mysql_query("select * from pending where id={$_GET['pending']} and denied=0",$c);
            $pend=mysql_fetch_array($getpendinfo);
            $getofferinfo=mysql_query("select * from offers where id={$pend['offer_id']}",$c);
            $off=mysql_fetch_array($getofferinfo);
            if(mysql_num_rows($getpendinfo)==0)
                    {
                        print"<center><br>Offer request not found or denied.</center>";
                        include"side.php";
                        include"footer.php";
                        exit;
                    }
            $time=time();
            $reward=$off['reward'];
            mysql_query("insert into completed values('','{$off['id']}','{$pend['user_id']}','','$time','{$off['reward']}')",$c);
            mysql_query("update users set total_earned=total_earned+$reward,current_balance=current_balance+$reward where id={$pend['user_id']}",$c) or die(mysql_error());
    
    [U]$referrer=mysql_query("select referrer from users where id={$pend['user_id']}",$c);
            mysql_query("update users set total_earned=total_earned+$reward,current_balance=current_balance+$reward where username={$referrer}",$c) or die(mysql_error());[/U]
    
            print"<center><br>Offer Approved</center>";
            mysql_query("delete from pending where id={$_GET['pending']}",$c);
        }
    The problem I am having deals with the underlined code. I want the code to add the reward, not only to the member, but also to the referrer. If the underlined code is remove, the rest of the script works fine. With it entered, I get the following error:
    MySQL version5.0.90

    Now I am lost. :cry: If additional info is needed, please let me know. Any help is appreciated.
     
  2. ziptrx

    ziptrx OSNN Addict

    Messages:
    53
    Probably wasting my time :disappointed:, but here's an update. I've changed some things and made some progress, but it is still not correct. I now have it updating but on the wrong user. :mad: Here's an example of what it should do: user3's referral is user1, user3 completes an offer, script should add credit to user3 and user1. Instead the script is giving credit to user3 and user2. Any help now, please? :laugh:





    Code:
    if($_GET['approve'])
        {
            $getpendinfo=mysql_query("select * from pending where id={$_GET['pending']} and denied=0",$c);
            $pend=mysql_fetch_array($getpendinfo);
            $getofferinfo=mysql_query("select * from offers where id={$pend['offer_id']}",$c);
            $off=mysql_fetch_array($getofferinfo);
            $getrefinfo=mysql_query("select * from users where id={$pend['user_id']}",$c) or die(print 'ERROR');
            $getref=mysql_fetch_array($getrefinfo);
            $tref=mysql_query("SELECT * FROM users WHERE `username`={$getref['referrer']}",$c);
            $theref=mysql_fetch_array($tref);
            if(mysql_num_rows($getpendinfo)==0)
                    {
                        print"<center><br>Offer request not found or denied.</center>";
                        include"side.php";
                        include"footer.php";
                        exit;
                    }
            $time=time();
            $reward=$off['reward'];
            mysql_query("update users set total_earned=total_earned+$reward,current_balance=current_balance+$reward where id={$theref['id']}",$c) or die(print 'REF ERROR');
            mysql_query("insert into completed values('','{$off['id']}','{$pend['user_id']}','','$time','{$off['reward']}')",$c);
            mysql_query("update users set total_earned=total_earned+$reward,current_balance=current_balance+$reward where id={$pend['user_id']}",$c) or die(mysql_error());
            print"<center><br>Offer Approved</center>";
            mysql_query("delete from pending where id={$_GET['pending']}",$c);
        }
     
  3. Johnny

    Johnny .. Commodore .. Political User

    Messages:
    5,015
    Location:
    Happy Valley
    I know nothing about PHP, so I am no help. Sorry :(