Jump to content

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

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.