Reply
Old July 10th, 2010 Top | #1
 
ziptrx's Avatar
OSNN Addict
Joined: January 2004
Posts: 53
Reputation: 0
Power: 103

Default PHP/SQL help

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());

$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());

        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. If additional info is needed, please let me know. Any help is appreciated.
ziptrx is offline   Reply With Quote
Old July 11th, 2010 Top | #2
 
ziptrx's Avatar
OSNN Addict
Joined: January 2004
Posts: 53
Reputation: 0
Power: 103

Default Re: PHP/SQL help

Probably wasting my time , 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. 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?





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);
    }
ziptrx is offline   Reply With Quote
Old July 13th, 2010 Top | #3
 
Johnny's Avatar
Paul Reed Smith
Joined: January 2004
Location: Happy Valley
Posts: 4,869
Reputation: 2369
Power: 173

Default Re: PHP/SQL help

I know nothing about PHP, so I am no help. Sorry

Paul Reed Smith.
Johnny is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules