Jump to content

[SOLVED] Need a little help with codeing a postback.php


PJdroopypants

Recommended Posts

I am using a site which when my users click on offers the site graps their id and sends a postback to my server wich updates my database. They also require a response of 1 or 0 because they keep sending the postback until they get a 1 response. Here is the code I have now which doesn't seem to work.

 

<?PHP
include 'dbcon.php'; //connect to database//
include 'classes.php';
$earn = ($_GET['new']);
$userid = ($_GET['uid']);
$totaluser = ($_GET['total']);
$offerid = ($_GET['oid']);
store_lead($_GET['new'], $_GET['uid'], $_GET['total'], $_GET['oid']); //see below function I have in "classes.php"//
$ok = store_lead($_GET['new'], $_GET['uid'], $_GET['total'], $_GET['oid']);
echo $ok?1:0;
?>
<?

//store_lead function in classes.php//
function store_lead($userid, $offerid){
$result = mysql_query("SELECT * FROM `surveys` WHERE `userid`='".$userid."' AND `offerid`='".$offerid."'");
$offerexist = mysql_num_rows($result);

if($offerexist == 0){
  $result = mysql_query("INSERT INTO `surveys` (`offerid`, `userid`, `totaluser`, `points`)"."VALUES ('$offerid', '$userid', '$totaluser', '$earn')");
  $result = mysql_query("UPDATE `mmfusers` SET points =points+ '".$earn."' WHERE `id`='".$userid."'"); //give user points//
  echo 1;
} else {
        echo 0;
}
}
?>

For starters store_lead only takes in 2 params and you're giving it 4.

 

Should be:

 

store_lead($_GET['uid'] ,$_GET['oid']);

 

I also don't know why you're assigning $ok to store_lead as it does NOT return anything.

That "echo 1" and "echo 0" should be "return 1" and "return 0".  Then the $ok assignment makes sense.  PJ, you'll need to give us some more information about how the script doesn't work for use to help.  Printing out your sql queries before running them would be a good start, as you can manually verify them.

For starters store_lead only takes in 2 params and you're giving it 4.

 

Should be:

 

store_lead($_GET['uid'] ,$_GET['oid']);

 

I also don't know why you're assigning $ok to store_lead as it does NOT return anything.

 

Thanks for the help guys, once i change the parameters in the function 2 all 4 and removed the echo from the postpack php it works fine now.

You mean once you changed the parameter to 2 instead of 4.  I also think btherl is right in that it looks like you should be returning 0 or 1 in the if else statement in your function because you're echoing

echo $ok?1:0;

 

When you could really just echo the function itself instead of using ternary operator.

 

In any case please mark as solved.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.