Jump to content

Postback.php help please.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
mastertate1

mastertate1

    Newbie

  • Members
  • Pip
  • 2 posts
Ok i keep having trouble trying to set up my POSTBACK.PHP and i cant seem to figure it out i have tried tons and tons of times to get it to work but i just cant figure it out when i test my post back i get this message and i have no idea what to do about it.

    <br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/ect0101/public_html/Diablo2/postback.php</b> on line <b>35</b><br /> 

Success: 108.0.249.224 earned 100 points and is referred by nobody

and i cannot see what is wrong at all if anything with that line 35 it is referring to

can someone please help me give me some advice because this is getting way to frustrating but i dont want to just give up on this project.

thanks to anyone for your suppost

Edited by Roger, 25 September 2010 - 05:52 PM.


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
foreach() must have an array as an argument, therefor the first variable in your foreach() statement is either a string or by mistake it was not set up to be an array.

Could you post the foreach() code section including the variable it is refering to within?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
Ruel

Ruel

    Newbie

  • Members
  • PipPip
  • 14 posts
the correct syntax for foreach is:

foreach ($arrary as $value) {
    echo $value;
    ...
}


#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
although, if $array is empty, foreach might fail unless $array isn't initialized with $array = array(); before populating it.
it can be helped by initialize it, or by typecasting: foreach ((array) $array as $value)
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
mastertate1

mastertate1

    Newbie

  • Members
  • Pip
  • 2 posts
@nullworm here is what i think you wanted me to post if this isnt it exactly just let me know and i will put up the right information.

thank you for the help.
<?php

/*

 * Basic Postback Example Script.

 * Copyright 2009. CPA Lead. All Rights Reserved

 */

 

$YOURPASSWORD = "*****"; //this is the password you set when creating your widget

$mysql_where = "******"; //hostname - usually localhost

$mysql_username = "*******"; //database username

$mysql_password = "******"; //database password

$mysql_database = "********"; //database name


$password = $_REQUEST['password'];

if ($password != $YOURPASSWORD) {

    echo "Access Denied";

    exit;

}


mysql_connect($mysql_where, $mysql_username, $mysql_password);

mysql_select_db($mysql_database);


/*

 * For a complete variable list see: [url=http://www.cpalead.com/postback-variables.php]Login - CPAlead[/url] (You must be logged in to view).

 */

include("includes.php");

$subid = $_REQUEST['subid'];

$survey = $_REQUEST['survey'];

$earn = $_REQUEST['earn'];

$pdtshow = $_REQUEST['pdtshow'];


//$query_getuserid = mysql_query("SELECT id from members WHERE username= '".$subid."'") or die(mysql_error());

//foreach(mysql_fetch_array($query_getuserid) as $userid);


$query_checkRef = mysql_query("SELECT referral_ID from members WHERE username= '".$subid."'") or die(mysql_error());

foreach(mysql_fetch_array($query_checkRef) as $ref_id_user);

if ($ref_id_user>=1)

{

mysql_query("UPDATE members SET points=points+".$pdtshow." WHERE username='".$subid."'");

mysql_query("UPDATE members SET completed_surveys=completed_surveys+1 WHERE username ='".$subid."'");

mysql_query("UPDATE members SET points=points+".$refer_points." WHERE id ='".$ref_id_user."'");

mysql_close();

echo "Success: ".$subid." earned ".$pdtshow." points\n and is referred by".$ref_id_user;

}else {

mysql_query("UPDATE members SET points=points+".$pdtshow." WHERE username='".$subid."'");

mysql_query("UPDATE members SET completed_surveys=completed_surveys+1 WHERE username ='".$subid."'");

mysql_close();

echo "Success: ".$subid." earned ".$pdtshow." points\n and is referred by nobody";

} 


?>

Edited by Orjan, 27 September 2010 - 12:02 AM.
Please use code or php tags while posting code


#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
You cannot use if ($ref_id_user>=1) on an array (that even may be empty), maybe you meant to use mysql_num_rows? Here is a simple example that may work on your situation, untested though:
$checkRef_query = mysql_query("SELECT referral_ID from members WHERE username= '".$subid."'") or die(mysql_error());
$checkRef_rows = mysql_num_rows($checkRef_query);

if($checkRef_rows > 0) {
    $checkRef_result= mysql_fetch_assoc($checkRef_query);
    mysql_query("UPDATE members SET points=points+".$pdtshow." WHERE username='".$subid."'");
    mysql_query("UPDATE members SET completed_surveys=completed_surveys+1 WHERE username ='".$subid."'");
    mysql_query("UPDATE members SET points=points+".$refer_points." WHERE id ='".$checkRef_result['referral_ID']."'");
    echo "Success: ".$subid." earned ".$pdtshow." points\n and is referred by".$checkRef_result['referral_ID'];
} else {
    mysql_query("UPDATE members SET points=points+".$pdtshow." WHERE username='".$subid."'");
    mysql_query("UPDATE members SET completed_surveys=completed_surveys+1 WHERE username ='".$subid."'");
    echo "Success: ".$subid." earned ".$pdtshow." points\n and is referred by nobody";
}
mysql_close();

?>
There are also other problems with the script, such as asking from $_REQUEST directly, which makes me suspect it is very old.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#7
Ruel

Ruel

    Newbie

  • Members
  • PipPip
  • 14 posts
Or you could use a variable to hold the result of your query, and verify if it has value or not using the isset() function.