Jump to content

Page showing nothing


dean7

Recommended Posts

Hey all, Been coding another script for my website which allows me to update a users Rank, allthough, when I try and view the page its giving me a White Blank Page. I carn't accually see whats wrong in my Script...

 

<?php
session_start();
include ("../includes/config.php");
include ("../includes/function.php");
logincheck();

ini_set ('display_errors', 1);
error_reporting (E_ALL);

$username = $_SESSION['username'];

// Owner Script - Change Users Rank

$userlevel = mysql_query ("SELECT * FROM users WHERE username = '$username' LIMIT 1") or die ("Error Finding Right Users " . mysql_error());
$levelright = mysql_fetch_object($userlevel);

// If userlevel isn't 5, move them on...	
if ($levelright->userlevel == "1" || $levelright->userlevel == "2" || $levelright->userlevel == "3" || $levelright->userlevel == "4"){
header ("Location: 404.php");
die();
}

// Start Change Rank...	
if (strip_tags($_POST['changerank'])){
$name = $_POST['name'];
$userchange = $_POST['userchange'];
			$real = mysql_query ("SELECT * FROM users WHERE username = '$userchange' LIMIT 1");
				$number = mysql_num_rows($real);
		if ($number != "1"){
		echo ("$userchange, is NOT registered! - Simple Words : No Such User!");
	}
if ($name == 1){
$reprand = rand(100, 50000);
mysql_query ("UPDATE users SET rank = 'Learner Driver (1)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 1

if ($name == 2){
$reprand = rand(50000, 200000);
mysql_query ("UPDATE users SET rank = 'Passed Driver (2)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 2

if ($name == 3){
$reprand = rand(200000, 500000);
mysql_query ("UPDATE users SET rank = 'New Driver (3)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 3

if ($name == 4){
$reprand = rand(500000, 2500000);
mysql_query ("UPDATE users SET rank = 'Speeding Driver (4)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 4

if ($name == 5){
$reprand = rand(2500000, 7000000);
mysql_query ("UPDATE users SET rank = 'Skilled Driver (5)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 5

if ($name == 6){
$reprand = rand(7000000, 20000000);
mysql_query ("UPDATE users SET rank = 'Maniac Driver (6)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 6

if ($name == 7){
$reprand = rand(20000000, 45000000);
mysql_query ("UPDATE users SET rank = 'Wanted Racer (7)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 7

if ($name == {
$reprand = rand(45000000, 90000000);
mysql_query ("UPDATE users SET rank = 'Pro Driver (' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 8

if ($name == 9){
$reprand = rand(90000000, 115000000);
mysql_query ("UPDATE users SET rank = 'Supreme Racer (9)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 9

if ($name == 10){
$reprand = rand(115000000, 150000000);
mysql_query ("UPDATE users SET rank = 'Super Supreme Racer (10)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 10

if ($name == 11){
$reprand = rand(150000000, 210000000);
mysql_query ("UPDATE users SET rank = 'Show Off Driver (11)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 11

if ($name == 12){
$reprand = rand(210000000, 280000000);
mysql_query ("UPDATE users SET rank = 'Extreme Show Off Driver (12)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 12

if ($name == 13){
$reprand = rand(280000000, 350000000);
mysql_query ("UPDATE users SET rank = 'Trained Driver (13)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 13

if ($name == 14){
$reprand = rand(350000000, 430000000);
mysql_query ("UPDATE users SET rank = 'Super Trained Driver (14)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 13

if ($name == 15){
$reprand = rand(430000000, 520000000);
mysql_query ("UPDATE users SET rank = 'Legendry Racer (15)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 15

if ($name == 16){
$reprand = rand(520000000, 600000000);
mysql_query ("UPDATE users SET rank = 'Most Legendry Racer (16)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 16

if ($name == 17){
$reprand = rand(600000000, 1000000000);
mysql_query ("UPDATE users SET rank = 'Official SD Legend (17)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 17

if ($name == 18){
$reprand = rand(1000000000, 1000000010);
mysql_query ("UPDATE users SET rank = 'Hidden Rank! (18)' AND rep = '$reprand' WHERE username = '$userchange'") or die ("Error Updating rank " . mysql_error());
} // Name 18

echo ("Successfully updated $userchange Rank!");
mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` , `saved` , `event_id` )
VALUES (
'', '$userchange', 'System', 'Your Rank has now been changed!', '$date', '0', '0', '0')") or die ("Error updating there inbox!" . mysql_error());

} // Rank Change

if (strip_tags($_POST['selectname'])){
$writenname = $_POST['nameinput'];
$rankinput = $_POST['rankinput'];
$repinput = $_POST['repinput'];
		$findme = mysql_query ("SELECT * FROM users WHERE username = '$writenname' LIMIT 1") or die ("Error Searching Names " . mysql_error());
			$found = mysql_num_rows($findme);
				if ($found != "1"){
					echo ("$writenname, isn't Registered! - Simple Terms : No Such User");
				}else{
		mysql_query	("UPDATE users SET rank = '$rankinput' AND rep = '$repinput' WHERE username= '$writenname'") or die ("Error Updating Rank + Rep " . mysql_error());
		echo ("$writenname Rank has now been changed!");
mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` , `saved` , `event_id` )
VALUES (
'', '$writenname', 'System', 'Your Rank has now been changed!', '$date', '0', '0', '0')") or die ("Error updating there inbox!" . mysql_error());
} // Found?	
} // Post selectname
?>
<html>
<head>
<title>Change Users Rank</title>
</head>
<body class='body'>
<form action='' method='POST' name='Change Rank'>
<table width='40%' border='1' cellpadding='0' cellspacing='0' class='table' align='center'>
<tr>
	<td class='header' align='center' colspan='2'>Change Users Rank?</td>
</tr>
<tr>
	<td class='omg' align='center'>This will change the users Current Rank!</td>
</tr>	
<tr>
	<td align='right'>Username:</td><td><input type='text' name='userchange' class='input'></td>
</tr>
<tr>
	<td><select name='name' size='1' class='dropbox'>
		<option value="1">Learner Driver (1)</option>
            <option value="2">Passed Driver (2)</option>
		<option value="3">New Driver (3)</option>
		<option value="4">Speeding Driver (4)</option>
		<option value="5">Skilled Driver (5)</option>
		<option value="6">Maniac Driver (6)</option>
		<option value="7">Wanted Racer (7)</option>
		<option value="8">Pro Driver (</option>
		<option value="9">Supreme Racer (9)</option>
		<option value="10">Super Supreme Racer (10)</option>
		<option value="11">Show Off Driver (11)</option>
		<option value="12">Extreme Show Off Driver (12)</option>
		<option value="13">Trained Driver (13)</option>
		<option value="14">Super Trained Driver (14)</option>
		<option value="15">Legendry Racer (15)</option>
		<option value="16">Most Legendry Racer (16)</option>
		<option value="17">Official SD Legend (17)</option>
		<option value="18">Hidden Rank! (18)</option></td>
</tr>
<tr>
	<td class='omg' align='center' colspan='2'><input type='submit' name='changerank' class='button'></td>
</tr>	
</table>
<br />
<table width='40%' border='1' cellpadding='0' cellspacing='0' class='table' align='center'>
<tr>
	<td class='header' align='center' colspan='2'>Change Rank?</td>
</tr>
<tr>
	<td class='omg' align='center'>This will change the <strong>posted</strong> users Rank and Rep!</td>
</tr>
<tr>
	<td align='right'>Username:</td><td><input type='text' name='nameinput' class='input'></td>
</tr>
<tr>
	<td align='right'>Rank:</td><td><input type='text' name='rankinput' class='input'></td>
</tr>
<tr>
	<td align='right'>Rep:</td><td><input type='text' name='repinput' class='input'></td>
</tr>
<tr>
	<td align='center' colspan='2'><input type='submit' name='selectname' class='button'></td>
</tr>
</table>	
</form>
</body>
</html>

 

Anyone able to see where I'm going wrong?

 

Thanks :)

Link to comment
Share on other sites

The two ini_set ('display_errors', 1); error_reporting (E_ALL); lines should be the first thing after your first <?php tag.

 

In fact, you should have those two settings in your master php.ini on your development system so that fatal parse errors will be displayed and so that you don't need to remember to put them into your code during development or forget to remove them when you put your code onto a live server.

Link to comment
Share on other sites

I also recommend that when you find yourself repeating blocks of code that only differ in the data values they are using, that you create an array to define the data. It will make your code much simpler and easy to add, change, or remove choices -

 

<?php
// Define your data using an array. You can add, change, or remove information by simply altering the array values, no need to change any of your actual php code
$data = array();
$data[1] = array('min'=>100,'max'=>50000,'title'=>'Learner Driver (1)');
$data[2] = array('min'=>50000, 'max'=>200000,'title'=>'Passed Driver (2)');
// ... repeat as needed ...
$data[18] = array('min'=>1000000000, 'max'=>1000000010,'title'=>'Hidden Rank! (18)');


// all your 18 sets of if() statements are replaced with the following few lines of code
if(isset($data[$name])){
// an entry exists
$reprand = rand($data[$name]['min'], $data[$name]['max']);
$query = "UPDATE users SET rank = '{$data[$name]['title']}', rep = '$reprand' WHERE username = '$userchange'";
mysql_query($query) or die ("Error Updating rank " . mysql_error());
} else {
// no entry was found ...
}


// produce the select menu options -
$options = '';
foreach($data as $key => $arr){
$options .= "<option value='{$key}'>{$arr['title']}</option>\n";
}

echo $options; // output the options inside the actual <select></select> menu
?> 

 

This results in one set of code, and in your case, since your query is incorrect (you have an AND in the SET column=value ... section), would let you fix that problem by changing only one line of code instead of needing to fix 18 of them.

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.