• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

PHP/SQL help

#1
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.
 
#2
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);
    }
 

Members online

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,016
Latest member
timpage