Ive been really struggling to see the issue with my postback script,
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//$adscendIp = "xx.xx.xx.xx"; // ip for adsc
//if($_SERVER['REMOTE_ADDR'] != $adscendIp)
//{
//die("Access Denied!");
//}
$campid = $_GET['campid']; // ID number of the campaign credited
$sid = $_GET['sid']; // The SubID that was passed in the campaign link
$rate = $_GET['rate']; // Commission earned (Will be negative if status is revoked)
$status = $_GET['status']; // Status of the lead. 1 for payable, 2 for revoked
$name = $_GET['name']; // Name of the campaign
$ip = $_GET['ip']; // IP address of the user
$cur = $_GET['cur'];
$sb1 = $_GET['sb1'];
if($status == "1")
{
mysqli_query($conn,"UPDATE users SET balance = '.$cur.' WHERE steamid = '.$sd1.'");
}
else
{
die("Revoked Lead!");
}
?>
Ive tried going to the link and putting the correct variables in the url and it seems to work, but when i try it on the offerwall its failing, is there anything you can see wrong with the script.
your all variable i.e campid, sid etc coming from any html form?
then in that form set method post. & then in php code get all parameters with $_POST...
$campid = $_POST['campid'];
$sid = $_POST['sid'];
$rate = $_POST['rate'];
Related
This question already has answers here:
Single result from database using mysqli
(6 answers)
Closed 5 months ago.
I am trying to retrieve some value from a column in the database.
The idea is to retrieve the IP of the person, then check their country, after that check the database if the country is blacklisted or not. There seems to be something wrong in the code, may you please give an advise?
This is the code:
<?php
//Get IP and country name
$ip=$_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("https://get.geojs.io/v1/ip/country/$ip.json"));
$country=$details->name;
$servername = "localhost";
$username = "My_Username";
$password = "My_password";
$dbname = "Database_name";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT country_name FROM uni_country";
$result = $conn->query($sql);
if (strpos($result, $country) == true) {
echo $country ." " . "is banned";
} else {
echo "Your country is not banned";
}
$conn->close();
?>
When I run it, it shows "Your country is not banned" - when it should actually say that my country is banned (I added a country to the database to test this).
The issue seems to be with reading the data from the database.
If I do echo $country; --> It actually shows my country, so it is retrieving it correctly (from geojs.io). But the code is not pulling the data from the database and verifying it.
Update:
If I do echo $result; the page returns Error 500.
Update
tried this new code, now it's saying that the country is not in the database, although it is actually there.
<?php
$ip=$_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("https://get.geojs.io/v1/ip/country/$ip.json"));
$country=$details->name;
$conn = mysqli_connect("localhost", "database", "password", "username");
$query = mysqli_query("SELECT * FROM `uni_country` WHERE country_name = '$country'");
if(mysqli_num_rows($query)>0) {
echo "Country Is in the database";
}
else {
echo "Country is not in the database";
}
?>
After trying for hours, this is the correct code:
<?php
$ip=$_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("https://get.geojs.io/v1/ip/country/$ip.json"));
$country=$details->name;
// Create connection
$servername = "localhost";
$username = "MyUsername";
$password = "MyPassword";
$database = "MyDatabase";
$conn = new mysqli($servername, $username, $password, $database);
$sql = "SELECT * FROM uni_country WHERE country_name ='$country'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "You country is currently banned.";
}
} else {
echo "Your country is not banned!";
}
?>
lets say if there are 13 records the latest 5 or from 9-13 in the first page,
from 4-8 in second page and 1-3 in the third page
i've tried this but its for the first page only
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mysqli_login";
// Create connection
$connection= new mysqli($servername, $username, $password, $dbname);
$query = mysqli_query($connection, "SELECT name,submittedby,trn_date FROM new_record ORDER BY id DESC LIMIT 5")or die(mysqli_error($connection));
while ($row = mysqli_fetch_array($query)) {
$fileName = $row['name'];
$fileContents = file_get_contents("txt/$fileName");
$poster = $row['submittedby'];
$date = $row['trn_date'];
echo ("posted by :$poster | posted date : $date");
echo ("$fileContents");
}
?>
Your code should be like this
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test_db";
// Create connection
$connection= new mysqli($servername, $username, $password, $dbname);
$current_page = 1; // 1=>refer to the first page, 2=> second page and so on..
if(!empty($_GET['page_no']){
$current_page = $_GET['page_no'];
}
$to = "5"; // it is no of record which you wants to show on each page, you can change it's value as per your need.
$from = ($current_page - 1) * $to;
$query = mysqli_query($connection, "SELECT name,submittedby,trn_date FROM new_record ORDER BY id DESC LIMIT $from , $to")or die(mysqli_error($connection));
while ($row = mysqli_fetch_array($query)) {
$fileName = $row['name'];
$fileContents = file_get_contents("txt/$fileName");
$poster = $row['submittedby'];
$date = $row['trn_date'];
echo ("posted by :$poster | posted date : $date");
echo ("$fileContents");
}
?>
your url should be something like http://localhost/projects/?page_no=1
replace "http://localhost/projects/" with your actual url
Hope this will help!!
Here's an article that discusses this topic. You need to offset your query based on the current page. So it will be LIMIT 5 OFFSET <amount based on the page>.
I have made a game in php in which people can upgrade their things the money would be deducted from their account. But when the money value becomes low, it goes in minus and the things are upgraded. Here is the code:
<?php
session_start();
include_once 'dbconnect.php';
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dbtest";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
?>
</html>
<head>
<body bgcolor="black">
<?php echo "<font color=\"#49fb35\" size=\"5\">Update Firewall Software $300</font><br>"; ?>
<font color="#49fb35" size="5">Upgrade Firewall.exe for $300</font>
</head>
</html>
How to stop the upgrade if the money value is low?
You can use PHP to verify that the value is more than 0, by using:
$query1 = "SELECT * from users WHERE user_id=".$_SESSION['user'];
$result = mysql_query($query1);
while($row = mysql_fetch_array($result)) {
// Get money from column
$money = $row['money'];
}
if($money >= 300) {
$query = "UPDATE users SET firewall = firewall + 1, money = money - 300 WHERE user_id=".$_SESSION['user'];
$update = mysqli_query($conn,$query);
} else {
// Prints error
echo 'Money is not enough to upgrade';
}
I'm not sure what variable name you are using, you can change accordingly, hope this helps!
I upload my script in my server and I made a new database in the same server.
the connection with database is working, but when the two script check or insert new value on the database doesn't working, but in localhost yes!!
<?php
require 'client/facebook.php';
$app_id = "***";
$secret = "***";
$app_url = "***";
// Create our Application instance
///jump the code
////////////////////////////////
$sdb = "***";
$db = "***";
$userdb = "***";
$passdb = "***";
$dblink = mysql_connect($sdb,$userdb,$passdb);
$seldb = mysql_select_db($db);
$username = $username; //user data
$UIDfaceboook =$id; //UID USER FACEBOOK FROM API
$user_type ="aa"; //USER DATA
$connection =""; //variable for start function check UID
$checkUIDdb ="INATTESA"; //check if exist the UID facebook
$insertnewuser ="";
$loadspecific ="inattesa";
///
///CHECK CONNECTION WITH DATABASE
///
$mysqlConnection = mysql_connect($sdb, $userdb, $passdb);
if (!$mysqlConnection)
{
echo "NO DATABASE FOUND, CHECK USER, PASS, DB";
}
else
{
echo "connection with database is ";
echo $connection = "ok";
mysql_select_db($db, $mysqlConnection);
}
//////////////////////////THIS FUNCTION DOESN'T WORK ONLINE
if ($connection = "ok"){
$con=mysqli_connect($sdb,$userdb,$passdb,$db);
$check="SELECT * FROM tabletest WHERE UIDfacebook = '$UIDfaceboook'";
$rs = mysqli_query($con,$check);
$data = mysqli_fetch_array($rs, MYSQLI_NUM);
if($data[0] > 1) {
echo "UID IN THE DATABASE ";
echo $checkUIDdb = "found";
}
else
{
echo "UID IN THE DATABASE ";
echo $checkUIDdb = "nofound";
}
}
///////////////THIS FUNCTION DOESN'T WORK ONLINE, and doesn't insert values
if($connection == "ok" && $checkUIDdb == "nofound"){
$username = strip_tags(mysql_real_escape_string($username));
$UIDfacebook = strip_tags(mysql_real_escape_string($UIDfaceboook));
$user_type = strip_tags(mysql_real_escape_string($user_type));
$sql = mysql_query("INSERT INTO `$db`.`tabletest` (`id`,`username`,`UIDfacebook`,`user_type`) VALUES ('','$username','$UIDfaceboook','$user_type');");
if($sql){
//The query returned true - now do whatever you like here.
echo $connection = "SAVE USERNAME, UID FACEBOOK AND USER TYPE ON DATABASE";
echo $loadspecific ="caricadati";
echo $insertnewuser = "yes";
}else{
//The query returned false - you might want to put some sort of error reporting here. Even logging the error to a text file is fine.
}
}else{
echo $connection = " CORRECT LOGIN WITH FACEBOOK";
}
mysql_close($dblink);
//Close off the MySQL connection to save resources.
?>
the echo php on my server said " connection with database is okUID IN THE DATABASE nofound" so, I don't understand when the variable $connect, $checkUIDdb is working don't load the script for insert a new user... I try to add my UID facebook in my database to check if the script jump this step, but the script ignore the database... just said that...
maybe the first problem is on $check="SELECT * FROM tabletest WHERE UIDfacebook = '$UIDfaceboook'";
but in localhost works..
thank you very much, i don't know what I can do...
first error i saw was this one:
//////////////////////////THIS FUNCTION DOESN'T WORK ONLINE
if ($connection = "ok"){
i guess you should edit this to
if ($connection == "ok"){
so you ask if $connection has the value "ok" and not if the allocation of "ok" to $connection has been done successfully.
Second error could be a mixture of "mysql" and "mysqli"...
hth
I'm trying to build a login process where, by using $_SESSION variables, the login credentials of the user are stored and used to show their relevant data from the database on screen (i.e. they will only see the school data that they work for).
<?php
session_start();
if(!isset($_SESSION['Initials'], $_SESSION['Surname']))
{
$host = "xxx";
$username = "xxx";
$password = "xxx";
$database_name = "xxx";
$table_name = "xxx";
mysql_connect($host, $username, $password) OR die("Can't
connect");
mysql_select_db($database_name) OR die("Can't connect to
Database");
$query = "SELECT Class FROM $table_name WHERE Initials = '".
$_SESSION['Initials']."' AND staff LIKE '%".$_SESSION['Surname']."'";
$result = mysql_query($query);
$class = mysql_fetch_array($result);
$count = mysql_num_rows($result);
if($count === NULL)
{
echo "ERROR";
}
else
{
$_SESSION['Class'] = $result;
echo "Class added to sessions";
}
}
?>
My initial problem where the query couldn't recognize the session variables was easily solved by adding the correct brackets for the if-statement. My next problem that has arisen here is that even though the query should be successfull (I don't receive an error message saying 'ERROR' when the $count is either FALSE or NULL) it's not creating the result array into a new session, because when I print the session array on a new page it's still only carrying over the 'Initials' and 'Surname' sessions.
What do I need to change to my query, or post-query process in order for that array (because it's bound to throw up multiple results) to be made into a new session?
Many thanks for the answers to my initial problem!
if(!isset($_SESSION['Initials'], $_SESSION['Surname'])) {
// code
}
u need { } brackets
if(!isset($_SESSION['Initials'], $_SESSION['Surname']))
$host = "xxxxx"; $username = "xxxxx"; $password = "xxxxx";
is
if(!isset($_SESSION['Initials'], $_SESSION['Surname'])) {
$host = "xxxxx";
}
$username = "xxxxx";
$password = "xxxxx";
I've found the answer - it turned out that I wasn't treating one of the session variables as a proper array and thus wouldn't load properly. I've added my script below so that people with similar problems in the future can use it as a reference point:
<?php
session_start();
// Server Details //
$host = "---";
$username = "---";
$password = "---";
$database_name = "---";
$table_name = "---";
// Connect Command //
mysql_connect($host, $username, $password) OR die("Can't
connect");
mysql_select_db($database_name) OR die("Can't connect to
Database");
// Query to call up the unique school name //
$query_school = mysql_query("SELECT DISTINCT School FROM $table_name
WHERE Initials = '".$_SESSION['---']."'
AND staff LIKE '%".$_SESSION['---']."'") or die( mysql_error());
$result_school = mysql_result($query_school, 0);
// Query to call up the unique centre no //
$query_centreno = mysql_query("SELECT DISTINCT CentreNo FROM
$table_name WHERE Initials = '".$_SESSION['---']."'
AND staff LIKE '%".$_SESSION['---']."'") or die( mysql_error());
$result_centreno = mysql_result($query_centreno, 0);
// The newly created sessions for school info //
$_SESSION['---'] = $result_school;
$_SESSION['---'] = $result_centreno;
// Query to call up the array of classes //
$query_class = mysql_query("SELECT Class FROM $table_name WHERE
Initials = '".$_SESSION['---']."'
AND staff LIKE '%".$_SESSION['---']."'") or die( mysql_error());
$query_class__array = array();
while($row = mysql_fetch_assoc($query_class))
$query_class_array[] = $row;
$_SESSION['---'] = $query_class_array;
?>