Jump to content

Random Events (bug)


Tenaciousmug

Recommended Posts

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 = "";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/235807-random-events-bug/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.