0

It's working great, but at some points after one of the random events goes through, I reload the page and it either gives me or takes away some starpoints without showing the message.. but it shows the message all the other times.
Could someone help me debug this and see why it's doing that?

<?php
include("config.php");

//To change the odds, change the second number in the rand() function.
$rand = rand(1,3);
if($rand == 1)
{
	$sql = "SELECT * FROM randomevents WHERE rarity <= '10'";
	$result = mysqli_query($cxn, $sql);
	//Write the events in here with the opener: $event[] = "#your event#";
	while ($row = mysqli_fetch_assoc($result))
	{
		$event[] = $row['phrase'];
	}
	
	//This will pick a random event and show it
	$renum = rand(0,count($event));
	$display = $event[$renum];
	
	if ($display == "")
	{
		$eventdisplay = "";
	}
	else
	{
		$eventdisplay = "<table cellspacing=\"0\" class=\"events\" align=\"center\"><br>
		<tr><br>
		<td><center><b><h1>Random Event</h1></b></center></td><br>
		</tr><br>
		<tr><br>
		<td><img src=\"".$_SERVER['SCRIPT_NAME']."\">
		<p><center>".$display."</center></p><br>
		</td><br>
		</table><br>";
		
		$sql = "SELECT type FROM randomevents WHERE phrase='".$display."'";
		$result = mysqli_query($cxn, $sql);
		$row = mysqli_fetch_assoc($result);
		if ($row['type'] == "gainsp")
		{
			$rand = rand(200,500);
			$sql = "UPDATE members SET starpoints = starpoints+$rand WHERE userid='".$_SESSION['userid']."'";
			mysqli_query($cxn, $sql) or die("Query died: updating starpoints");
		}
		elseif ($row['type'] == "losesp")
		{
			$rand = rand(50,100);
			$sql = "UPDATE members SET starpoints = starpoints-$rand WHERE userid='".$_SESSION['userid']."'";
			mysqli_query($cxn, $sql) or die("Query died: updating starpoints");
		}
		else
		{}
	}
}
else
{
	$eventdisplay = "";
}
?>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by cuonic
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.