$_GET['action'] Error

The case value seems to be ignored

Page 1 of 1

8 Replies - 3084 Views - Last Post: 04 January 2010 - 10:28 AM Rate Topic: -----

#1 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

$_GET['action'] Error

Posted 04 January 2010 - 09:20 AM

Hello,

I'm trying to make a battle report script for my online game. I'm using the $_GET['action'] variable to separate the different battle reports, displaying a list of all available reports as a default case. My problem is that I can't get the script to see the value for the case, so that when a link in the list is clicked, the user is returned to the default case value.

I hope you understand my problem. If not, please ask ;)

<?php 
session_start(); 
include("database.php");
include("login.php");
if($logged_in){
	$name = $_SESSION['username'];
	
	$conn;
	$q = "select * from attacks where attacker = '$name' or defender = '$name'";
	$res = mysql_query($q,$conn);
	$row = mysql_fetch_array($res);

switch($_GET['action']) {
	case $row['time']:
		$a = "select * from attacks where attacker = '$name' or defender = '$name' and time = '$row[time]'";
		$res1 = mysql_query($a,$conn);
		$arr = mysql_fetch_array($res1);
		echo "$arr[attacker]...$arr[defender]....$arr[atkloss]...$arr[defloss]...$arr[loot]<br />";
		break;
		
	default:
		while($row = mysql_fetch_array($res)){
			echo "<a href=reporter.php?action=$row[time]>$row[time]</a><br />";
		}
		break;
	}
}
else{
	die("You may not access this page unless you are logged in.");
}
?>


Thanks in advance.

This post has been edited by Cbeppe: 04 January 2010 - 09:22 AM


Is This A Good Question/Topic? 0
  • +

Replies To: $_GET['action'] Error

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: $_GET['action'] Error

Posted 04 January 2010 - 09:22 AM

I can almost certainly guarantee you that the value of $_GET['action'] is NOT going to be $row['time'].

Quote

switch($_GET['action']) {
	case $row['time']:



It isn't being ignored, you just want or expect the code to behave differently than it is.
Was This Post Helpful? 0
  • +
  • -

#3 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: $_GET['action'] Error

Posted 04 January 2010 - 09:26 AM

Thanks for confirming my fears No2pencil ;)

I suspected it was something with the $row[time] variable. Now the problem is: How would I change it? What would I add/change/delete to fix this?

Thanks for a super-fast answer, it's really appreciated.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: $_GET['action'] Error

Posted 04 January 2010 - 09:27 AM

Before throwing a switch case on your $_GET action array element, why don't you echo it out, so you can see what it is. Then you'll have a better understanding how to case the value.

For example :

die("Checking $_GET['action'] for the value $row['time']");
switch($_GET['action']) {
	case $row['time']:


Was This Post Helpful? 0
  • +
  • -

#5 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: $_GET['action'] Error

Posted 04 January 2010 - 09:41 AM

I see what you mean. The $row['time'] varaible seems to be a single value and the one missing from my list... I'm sorry to say, I'm even more confused. I'm clueless as to how to check for a case (although I might be able to work on that) but even more confused as to why the first $row['time'] variable doesn't appear on my list.

Do you have any ideas?

Again, thanks a lot for your help.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: $_GET['action'] Error

Posted 04 January 2010 - 09:43 AM

What are the complete possibilities that the $_GET['action'] variable can hold? Can you list them here?
Was This Post Helpful? 0
  • +
  • -

#7 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: $_GET['action'] Error

Posted 04 January 2010 - 09:56 AM

I believe it is a part of an array ($_GET), which means it can hold any single value. That means that my problem is that I am trying to make it hold an entire array, something it can't do.

So then, if I get you right, I must change the $row['time'] into a single variable which can be a part of the $_GET array. How would I do that and still make it check for all possible values of my $row array?

This post has been edited by Cbeppe: 04 January 2010 - 09:56 AM

Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: $_GET['action'] Error

Posted 04 January 2010 - 10:11 AM

No what I am suggesting is that you use the select case function correctly, & case for more than just one variable. Run a case for each one, or use an if/than/else structure.
Was This Post Helpful? 0
  • +
  • -

#9 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: $_GET['action'] Error

Posted 04 January 2010 - 10:28 AM

Ok, I'll get to it. Thanks a lot for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1