PHP/SQL help

ziptrx

OSNN Addict
Joined
7 Jan 2004
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:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id #19' at line 1
MySQL version5.0.90

Now I am lost. :cry: If additional info is needed, please let me know. Any help is appreciated.
 
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);
    }
 
I know nothing about PHP, so I am no help. Sorry :(
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back