PHP help. :\

Posts 16 of 6 · Page 1 of 1
PHP help. :\
I started a C#/PHP loader ages ago for private use, I figured it would be a good chance to learn some php, Once I was going to complete it I was planing on uploading it. Anyway, I'm currently stuck on a error what's really annoying me. :\ I wouldn't call it a error so much as a "bug".

This is the code:
also, i kno is vaun to sql injection. don't really care atm
 
codezin


http://pastebin.com/A1r6DmHu

Code:
$cheatsownedinfo_query = $sqlConnection->query("SELECT * FROM `ownedcheats` WHERE `username`='$username'");

if($cheatsownedinfo_query->num_rows == 0){
	die($CHEATSOWNED_NoCheatsOwned);
}

$validCheats_count = 0;

while($ownedCheats_index = $cheatsownedinfo_query->fetch_assoc()){
	date_default_timezone_set("Australia/Sydney");
	if($ownedCheats_index['isExpiryUnlimited'] == 'false'){
		if($ownedCheats_index['expiryDate'] <= date("Y-m-d")){
			continue;
		}
	}

	$allCheatsQuery = $sqlConnection->query("SELECT * FROM `cheats` WHERE `cheatName`='".$ownedCheats_index['cheatName']."'");
	if($allCheatsQuery->num_rows == 0){//row '68'
		continue;
	}

	while($currentCheatInfo = $allCheatsQuery->fetch_assoc()){
		echo Base64_EncodeUrlSafe($ownedCheats_index['expiryDate']) . ":";
		echo Base64_EncodeUrlSafe($currentCheatInfo['Name']) . ":";
		echo Base64_EncodeUrlSafe($currentCheatInfo['targetprocess']) . ":";
		echo Base64_EncodeUrlSafe($currentCheatInfo['credits']) . "\t";

		$validCheats_count++;
	}
}

if($validCheats_count == 0){
	die($CHEATSOWNED_AllExpired);
}


And this is the result I get:


I'm completely lost with what's happening. I got a simple understanding with what's happening, But eh, plox help.

I would like to note at the time of typing this I'm sick with conjunctivitis. Today it's starting to get better so that's why I'm able to do this, But my throat is still getting more sore/swollen. And it sucks because the panadol I'm taking only allows me to take it every 8 hours, But starts to wear off after 4 hours :\
http://php.net/manual/en/mysqli.query.php

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
Basically, your query failed for some reason. For debugging print your statement before calling query or look into the sql server's log. If it's a bug for some values only, simply check the value before trying to access properties and exit if it's false or null.

Code:
if (!($allCheatsQuery = $sqlConnection->query(...)))
{ 
  die("Errr...");
}
Quote Originally Posted by Silent View Post
Code:
$allCheatsQuery = $sqlConnection->query("SELECT * FROM `cheats` WHERE `cheatName`='".$ownedCheats_index['cheatName']."'");
	if($allCheatsQuery->num_rows == 0){//row '68'
		continue;
	}
The query did not succeed. To get an incentive to locate the problem you should use a $sqlConnection->error.

also, i kno is vaun to sql injection. don't really care atm
The solution is to aggregate bind_param with prepared statements.
Put this line before

die("SELECT * FROM `cheats` WHERE `cheatName`='".$ownedCheats_index['cheatName']."'");
$allCheatsQuery = $sqlConnection->query("SELECT * FROM `cheats` WHERE `cheatName`='".$ownedCheats_index['cheatName']."'");
Run the output in Phpmyadmin and see what happens
Turns out I forgot how to spell.


@Hugo Boss Solved :P
Posts 16 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?