PJdroopypants Posted December 30, 2008 Share Posted December 30, 2008 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138933-solved-need-a-little-help-with-codeing-a-postbackphp/ Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138933-solved-need-a-little-help-with-codeing-a-postbackphp/#findComment-726611 Share on other sites More sharing options...
btherl Posted January 4, 2009 Share Posted January 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/138933-solved-need-a-little-help-with-codeing-a-postbackphp/#findComment-729282 Share on other sites More sharing options...
PJ droopy pants Posted January 5, 2009 Share Posted January 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/138933-solved-need-a-little-help-with-codeing-a-postbackphp/#findComment-730018 Share on other sites More sharing options...
Maq Posted January 5, 2009 Share Posted January 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/138933-solved-need-a-little-help-with-codeing-a-postbackphp/#findComment-730020 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.