Jump to content

How can the same code not work twice?


CrazeD

Recommended Posts

This is pissing me off beyond belief.

 

So my admin area of my site is being fricken retarded. I'm trying to add a news feature, so admins can add/edit/delete news topics that come up on the front page. It works but not when I make it so you have to be admin/logged in.

 

Now, I used the EXACT SAME METHOD that I did before and now it doesn't work? WTF?!

 

I have this:

 

<?php

if ($_SESSION['user_level'] == 1) {
admin stuff
admin stuff
admin stuff
admin stuff
} else {
     print '<p>Must be logged in as an admin to view this page!</p>';
}

?>

 

That's basically what I have. It works fine on one script, but not the other...

 

I thought PHP was supposed to be reliable? How can code work once but then not work again?

 

I even made a file with just this in it:

<?php

if ($_SESSION['user_level'] == 1 ){

print 'WTF';

}

?>

And that doesn't work, yet my other admin page works.

 

Just for the record, here's the page that does work:

 

<?php

		require_once('mysql.php');

		if (isset ($_SESSION['username'])) {

			if ($_SESSION['user_level'] == 1 ) {

				if (isset ($_POST['submit'])) {

				$query = "INSERT INTO pr0n_record ( pr0n_record_id, clan_name, size, map, our_score, their_score, date ) VALUES ( 0, '{$_POST['clan_name']}', '{$_POST['size']}', '{$_POST['map']}', '{$_POST['our_score']}', '{$_POST['their_score']}', '{$_POST['date']}' )";

				if (@mysql_query ($query)) {

					print 'A scrim has been added to the record!<br />
						<a href="manage_record.php">Back</a>';


				} else { // MySQL Error

					die ('<p>An error has occured:<b> ' . mysql_error() . '</b></p<');

				}

				} else { // Submit not set

					print "<form method=\"post\" action=\"manage_record.php\">

					<table border=\"1\" bordercolor=\"#000000\" width=\"545\">
						<tr>
							<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Clan Name:</font></td>
							<td align=\"center\"><input type=\"text\" name=\"clan_name\" /></td>
						</tr>

						<tr>
							<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Size:</font></td>
							<td align=\"center\"><input type=\"text\" name=\"size\" /></td>
						</tr>

						<tr>
							<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Map Played:</font></td>
							<td align=\"center\"><select name=\"map\">
													<option value=\"please_choose\" selected=\"selected\">Choose A Map...</option>
													<option value=\"obj/\">--- Objective ---</option>
													<option value=\"obj/obj_team1\">The Hunt</option>
													<option value=\"obj/obj_team2\">V2 Rocket Facility</option>
													<option value=\"obj/obj_team3\">Omaha Beach</option>
													<option value=\"obj/obj_team4\">The Bridge</option>
													<option value=\"tdm\">--- Team Death Match ---</option>
													<option value=\"dm/mohdm1\">Southern France</option>
													<option value=\"dm/mohdm2\">Destroyed Village</option>
													<option value=\"dm/mohdm3\">Remagen</option>
													<option value=\"dm/mohdm4\">Crossroads</option>
													<option value=\"dm/mohdm5\">Snowy Park</option>
													<option value=\"dm/mohdm6\">Stalingrad</option>
													<option value=\"dm/mohdm7\">Algiers</option>
												</select></td>
						</tr>

						<tr>
							<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Our Score:</font></td>
							<td align=\"center\"><input type=\"text\" name=\"our_score\" /></td>
						</tr>

						<tr>
							<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Their Score:</font></td>
							<td align=\"center\"><input type=\"text\" name=\"their_score\" /></td>
						</tr>

						<tr>
							<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"3\">Date Played:</font></td>
							<td align=\"center\"><input type=\"text\" name=\"date\" /></td>
						</tr>
						</table>
						<br /><br />
						<center><input type=\"submit\" name=\"submit\" value=\"Submit!\" /></center>
						</form><br /><br />";

				}

			print '<table border="1" bordercolor="#000000" width="545">

			<tr>
				<td align="center"><font color="#707070" face="Arial" size="2"><b>Clan Name</b></font></td>
				<td align="center"><font color="#707070" face="Arial" size="2"><b>Size</b></font></td>
				<td align="center"><font color="#707070" face="Arial" size="2"><b>Map</b></font></td>
				<td align="center"><font color="#707070" face="Arial" size="2"><b>Result</b></font></td>
				<td align="center"><font color="#707070" face="Arial" size="2"><b>Date Played</b></font></td>
				<td align="center"><font color="#707070" face="Arial" size="2"><b>Edit/Delete</b></font></td>
			</tr>';

			$get_query = 'SELECT * FROM pr0n_record ORDER BY pr0n_record_id DESC';

				if ($r = mysql_query ($get_query)) {

					while ($row = mysql_fetch_array ($r)) { 

							print "<tr>
								<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['clan_name']}</font></td>
								<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['size']}</font></td>
								<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['map']}</font></td>
								<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['our_score']} - {$row['their_score']}</font></td>
								<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">{$row['date']}</font></td>
								<td align=\"center\"><font color=\"#707070\" face=\"Arial\" size=\"2\">
								<a href=\"edit_record.php?id={$row['pr0n_record_id']}\">Edit</a>/<a href=\"delete_record.php?id={$row['pr0n_record_id']}\">Delete</a></font></td>

								</tr>";

					}

					} else { // MySQL Error

						die ('<p>An error has occured:<b> ' . mysql_error() . '</b></p>');

					}

					mysql_close();

				} else { // Not admin

					print '<p>You do not have access to this page!</p>';

				}

			} else { // Not logged in

				print '<p>You must be logged in as an admin to view this page!<br />
						<a href="/login.php">Click here</a> to login.</p>';

			}




		?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/42480-how-can-the-same-code-not-work-twice/
Share on other sites

I have two different scripts that both use the exact same code. They start with

 

if ($_SESSION['user_level'] == 1) {

 

and then it has all the stuff I want only admins to be able to do. One script works, the other one does not. It's the EXACT same code, I even copy/pasted it.

 

I don't understand how this is possible...

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.