trouble using data from url and inserting it to database

Discussion in 'MySQL' started by aedges, Nov 20, 2010.

  1. #1
    I am trying to use callback url's to insert users into my database.

    Example of my callback url: (note i can not change this as it is created by a site i do not own tapjoy if its important)

    http://facebook.0dollerhost.com/postback.php?snuid=test&currency=111&id=A1B2C3D4&verifier=30af489b51e0c653d65aeb41c071ad95 
    
    Code (markup):
    i need it to add snuid to userid and currency to points.
    but if the userid exists then just update points


    here is what is already in the script

    
    include('config.php'); 
    
    $subid = $_POST['snuid'];
    $points = $_POST['currency'];
    $earn = $_POST['id'];
    $type = $_POST['verifier'];
    $campaign = ['0dolelr'];
    echo $subid.' earned '.$points.' points';
    
    // Log postback results into our history
    mysql_query("INSERT INTO `history` VALUES(null,'".time()."','".$subid."','".$points."','".$earn."','".$type."','".$campaign."')");
    
    // Adjust user points
    if ($points > 0) {
     $query = mysql_query("SELECT * FROM `user` WHERE `userid` = '".addslashes($subid)."'");
     if (mysql_affected_rows() > 0) {
      $row = mysql_fetch_assoc($query);
      mysql_query("UPDATE `user` SET `points` = '".($row['points'] + $points)."' WHERE `userid` = '".addslashes($subid)."'");
     }
     else
     {
      mysql_query("INSERT INTO `user` VALUES('".addslashes($subid)."','".$points."')");
     }
    }
    
    Code (markup):

    it does not give any output from @echo $subid.' earned '.$points.' points';@
    nor does it add anything to the database if the user doe or does not exist.

    How can i fix this?
    also i have checked config several times and there is no error there

    Many thanks
     
    aedges, Nov 20, 2010 IP
  2. ZoomRumble

    ZoomRumble Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this

    
    include('config.php'); 
    
    $subid = $_REQUEST['snuid'];
    $points = $_REQUEST['currency'];
    $earn = $_REQUEST['id'];
    $type = $_REQUEST['verifier'];
    $campaign = ['0dolelr'];
    echo $subid.' earned '.$points.' points';
    
    // Log postback results into our history
    mysql_query("INSERT INTO `history` VALUES(null,'".time()."','".$subid."','".$points."','".$earn."','".$type."','".$campaign."')");
    
    // Adjust user points
    if ($points > 0) {
     $query = mysql_query("SELECT * FROM `user` WHERE `userid` = '".addslashes($subid)."'");
     if (mysql_affected_rows() > 0) {
      $row = mysql_fetch_assoc($query);
      mysql_query("UPDATE `user` SET `points` = '".($row['points'] + $points)."' WHERE `userid` = '".addslashes($subid)."'");
     }
     else
     {
      mysql_query("INSERT INTO `user` VALUES('".addslashes($subid)."','".$points."')");
     }
    }
    
    PHP:
     
    ZoomRumble, Nov 24, 2010 IP
  3. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    It needs to be $_GET if it needs to be from the url. Or as suggested $_REQUEST if you want it to work for both post and get
     
    iama_gamer, Nov 28, 2010 IP