Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.