orre Posted April 16, 2011 Share Posted April 16, 2011 I got a script that receive info from paypal "ipn" when someone is making a payment from my shop. I wanted to edit the script a bit as i am adding a bonus system to it. After i added // Bonus system vars if ($item_name == '301') { $point == "1"; } elseif ($item_name == '302') { $point == "2"; } elseif ($item_name == '303') { $point == "3"; } elseif { $point == "0"; } And $bonus1 = "update Bonus set points=points+'$points' where username='$username'"; mysql_query("$bonus1"); $bonus2 = "update Bonus set points_total=points_total+'$points' where username='$username'"; mysql_query("$bonus2"); $bonus3 = "update Bonus set $item_name=$item_name+1 where username='$username'"; mysql_query("$bonus3"); The script wont work. But it does when i remove those things. I think my problem is at the if,elseif i just dont know why. Do i need to put it in some kind of while loop? Here is the full php code mysql_connect('xxxxx', 'xxxx', 'xxxxxx'); $notify_email = "xxxx@xxxx"; // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); // assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $buyer_firstname = $_POST['first_name']; $buyer_lastname = $_POST['last_name']; $timestamp = $_POST['payment_date']; $address_street = $_POST['address_street']; $address_city = $_POST['address_city']; $address_state = $_POST['address_state']; $address_zip = $_POST['address_zip']; $username = $_POST['custom']; // Bonus system vars if ($item_name == '301') { $point == "1"; } elseif ($item_name == '302') { $point == "2"; } elseif ($item_name == '303') { $point == "3"; } elseif { $point == "0"; } mysql_select_db('redlite'); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if ($payment_status == 'Completed') { $sql = "insert into tblMail values ('','$txn_id','$payer_email',' $item_name','$timestamp','','','','$payment_amount $payment_currency','$buyer_firstname $buyer_lastname','$address_street $address_city , $address_state $address_zip','','','$username')"; mysql_query("$sql"); $bonus1 = "update Bonus set points=points+'$points' where username='$username'"; mysql_query("$bonus1"); $bonus2 = "update Bonus set points_total=points_total+'$points' where username='$username'"; mysql_query("$bonus2"); $bonus3 = "update Bonus set $item_name=$item_name+1 where username='$username'"; mysql_query("$bonus3"); $ttlpay_sql = "update totalpay set total=total+'$payment_amount' where id='1'"; mysql_query("$ttlpay_sql"); mail($notify_email, "CLVerified", "$res\n $req"); } else { mail($notify_email, "CLVerified - But not completed". "$res\n $req"); } } else if (strcmp ($res, "INVALID") == 0) { mail($notify_email, "CLINVALID IPN", "$res\n $req"); } } fclose ($fp); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233919-ifelseifelse-and-some-basic-mysql-question/ Share on other sites More sharing options...
Pikachu2000 Posted April 16, 2011 Share Posted April 16, 2011 if/elseif/elseif/else not if/elseif/elseif/elseif Quote Link to comment https://forums.phpfreaks.com/topic/233919-ifelseifelse-and-some-basic-mysql-question/#findComment-1202417 Share on other sites More sharing options...
Skewled Posted April 16, 2011 Share Posted April 16, 2011 // Bonus system vars if ($item_name == '301') { $points == "1"; } elseif ($item_name == '302') { $points == "2"; } elseif ($item_name == '303') { $points == "3"; } else { $points == "0"; } You're establishing $point in your if else statments but your calling $points in your query. So change the above $point to $points and give it a go. I also corrected your if/else .. it's if/elseif/elseif/else in your case. Quote Link to comment https://forums.phpfreaks.com/topic/233919-ifelseifelse-and-some-basic-mysql-question/#findComment-1202418 Share on other sites More sharing options...
orre Posted April 16, 2011 Author Share Posted April 16, 2011 Thanks! I did have if,elseif,elseif,else in my first try. forgot the edit it back was playing with it sorry. Now the script works agin after i fixed the $points But it still doesnt insert Those lines at all. $bonus1 = "update Bonus set points=points+'$points' where username='$username'"; mysql_query("$bonus1"); $bonus2 = "update Bonus set points_total=points_total+'$points' where username='$username'"; mysql_query("$bonus2"); $bonus3 = "update Bonus set $item_name=$item_name+1 where username='$username'"; mysql_query("$bonus3"); But it do insert $ttlpay_sql = "update totalpay set total=total+'$payment_amount' where id='1'"; mysql_query("$ttlpay_sql"); So my question is, is there a way to echo my varibels to a file? some how lets say "print $bonus1 " And it would print something like "update Bonus set points=points+'1' where username='testuser" For debbuging. Cuse i cant se any errors at all the Table is named Bonus and when i try to run update Bonus set points=points+'1' where username='testuser in my MYSQL it works. I know this is basic stuff, am reading some tutorials atm, but i like the "learn by doing" Thanks /Orre Quote Link to comment https://forums.phpfreaks.com/topic/233919-ifelseifelse-and-some-basic-mysql-question/#findComment-1202424 Share on other sites More sharing options...
orre Posted April 16, 2011 Author Share Posted April 16, 2011 n/m i figured it out with the print command. update Bonus set points=points+'' where username='lotan' update Bonus set points_total=points_total+'' where username='lotan' update Bonus set 301=301+1 where username='lotan' ( found the error on this one took the $item_number out) This is what it output. So the if,elseif things dont seem to work proper for some reson. Or do i need to have them in the same while function? Quote Link to comment https://forums.phpfreaks.com/topic/233919-ifelseifelse-and-some-basic-mysql-question/#findComment-1202433 Share on other sites More sharing options...
orre Posted April 17, 2011 Author Share Posted April 17, 2011 After playing with it for a while i made it look ugly but it works. Is there way to get it look better? Do i need to use some kind of loop? Heres the code that works. if ($item_number == '301') { $bonus1 = "update Bonus set points=points+'1' where username='$username'"; mysql_query("$bonus1"); $bonus2 = "update Bonus set points_total=points_total+'1' where username='$username'"; mysql_query("$bonus2"); $bonus3 = "update Bonus set smal_turns='smal_turns'+1 where username='$username'"; mysql_query("$bonus3"); } elseif ($item_number == '302') { $bonus1 = "update Bonus set points=points+'2' where username='$username'"; mysql_query("$bonus1"); $bonus2 = "update Bonus set points_total=points_total+'2' where username='$username'"; mysql_query("$bonus2"); $bonus3 = "update Bonus set medium_turns='medium_turns'+1 where username='$username'"; mysql_query("$bonus3"); } elseif ($item_number == '303') { $bonus1 = "update Bonus set points=points+'3' where username='$username'"; mysql_query("$bonus1"); $bonus2 = "update Bonus set points_total=points_total+'3' where username='$username'"; mysql_query("$bonus2"); $bonus3 = "update Bonus set big_turns='big_turns'+1 where username='$username'"; mysql_query("$bonus3"); } else { $bonus1 = "update Bonus set points=points+'0' where username='$username'"; mysql_query("$bonus1"); $bonus2 = "update Bonus set points_total=points_total+'0' where username='$username'"; mysql_query("$bonus2"); Quote Link to comment https://forums.phpfreaks.com/topic/233919-ifelseifelse-and-some-basic-mysql-question/#findComment-1202446 Share on other sites More sharing options...
Skewled Posted April 17, 2011 Share Posted April 17, 2011 Glad I could help you, the code looks good for what's needed.. I can't think of anyway to make it appear any better. Quote Link to comment https://forums.phpfreaks.com/topic/233919-ifelseifelse-and-some-basic-mysql-question/#findComment-1202492 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.