Jump to content

Theres a bug between the 2 $_REQUEST I think


jpraj

Recommended Posts

This is a small game i'm working to practice, but I'm founding a problem between "fround" and "sround"  :( hope you can help me.

<?php

$playerid = 1;//test id
require_once ("dbconnect.php");


$action = $_REQUEST["action"];
/**													 			Functions 			   															**/

function rock($round){
echo "<form method=\"post\" action=\"rydar.php?action={$round}\">";
echo "<input type=\"text\" name=\"guess\" id=\"guess\"> ";
echo "<input type=\"submit\" value=\"submit\">";
echo "</form>";
}
function rockwin(){
$win = mysql_query("SELECT gamewon FROM isitar WHERE id = {$playerid} ");

if ($win['gamewon'] == 0){

	mysql_query("UPDATE isitar SET  gamewon = 1 WHERE id = {$playerid} ");

}
if($win['gamewon'] == 1){

	mysql_query("UPDATE isitar SET , gamewon = 2 WHERE id = {$playerid} ");
	echo "You have a really great eye! ";
}
if($win['gamewon'] == 2){
	echo "You won 3 times, you are now the best";
}
}
/**                                                     End Functions  															**/


$rock = rand(1,3);

mysql_query("UPDATE isitar SET gametry = 0, roundwin= 0 WHERE id = {$playerid}");
if ($action == ""){

	echo "come and play, its a 2 out of 3 wins to get the prize, want to try it?";
	rock("fround");
	echo "{$rock}"; // for testing 
}
}
if ($action == "fround"){
$query = mysql_query("SELECT gametry FROM isitar WHERE id = {$playerid}");
$game = mysql_fetch_row($query);

	if($_POST["guess"] <= 0 || $_POST["guess"] > 4   ){
		echo "That rock doesn't existes.. Don't fool with me. Let's try again";
		rock("fround");
	}

	elseif($_POST["guess"] == $rock){
		echo "Congrats, you have found the rock, if you find it 1 more time you will win, 2 try, lets go, choose.";
		rock("sround");
		mysql_query("UPDATE isitar SET gametry = 1,roundwin = 1 WHERE id = {$playerid}");


	}	
	elseif ($_POST["guess"] != $rock ){
		echo "Sorry, you miss, it was on " . $_POST["guess"] . " you still got 2 more trys, lets go, choose.";
		rock("sround");
		mysql_query("UPDATE isitar SET gametry = 1 WHERE id = {$playerid}");
	}
}
														/** Second round **/
if($action == "sround"){
$query = mysql_query("SELECT roundwin,gametry FROM isitar WHERE id = {$playerid}");
$game = mysql_fetch_row($query);
if($game['1'] == 1){
	if($_POST["guess"] <= 0 || $_POST["guess"] >= 4){
		rock("sround");
	}
	elseif ($_POST["guess"] == $rock ){

		if($game['0'] == 1){
			rockwin();
		}
		elseif($game['0'] == 0){
			echo "Congrats, you have found the rock, if you find it 1 more time you will win , 1 try left, lets go, choose.";
			rock("tround");
			mysql_query("UPDATE isitar SET gametry = 2,roundwin = 1 WHERE id = {$playerid}");
		}

	}			

	elseif ($_POST["guess"] != $rock){
		if($game['0'] == 1){
			echo "Sorry, you miss, it was on " . $_POST["guess"] . " you still got 1 more try, lets go, choose.";
			rock("tround");
			mysql_query("UPDATE isitar SET gametry = 2 WHERE id = {$playerid}");
		}
		elseif($game['0'] == 0){
			echo "Sorry, it seems you lost, it was on " . $_POST["guess"] . " it was the last chance you had to win 1 round, you lose, sorry.";
			mysql_query("UPDATE isitar SET gametry = 0, roundwin=0 roundwin WHERE id = {$playerid}");

		}
	}

}
}
									/** Third Round  **/
if ($action == "tround"){
$query = mysql_query("SELECT gametry FROM isitar WHERE id = {$playerid}");
$game = mysql_fetch_row($query);
if($game['0'] == 2){
	if($_POST["guess"] <= 0 || $_POST["guess"] >= 4){
		echo "hi";
		//rock("tround");
	}
	if ($_POST["guess"] != $rock ){
		echo "Ahh, sorry, it isn't you lucky day it seems.. Good luck next time";

	}
	if ($_POST["guess"] == $rock ){
		rockwin();

	}

}		
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.