Jump to content

$_GET default


Lumit

Recommended Posts

hello,

First off I'm new here so I'm sorry if this is the wrong place to ask this, but this looks like the right place...

 

I want to know what happens when you are using GET but nothing is added to the url. What is the value set to if it isn't told anything else?

 

thanks,

Lumit

Link to comment
Share on other sites

$_GET['cat'] == "" is also true if cat was not set at all.  So in this case you should use isset().

 

Another option is to check $_GET['cat'] === null (note the 3 =, not 2 =.  3 = is a very strict comparison).  If it is === null, then it was not set.

Link to comment
Share on other sites

Alright, I'm still having some trouble pinpointing the problem.

 

I'm trying to make a tic-tac-toe script. I'm trying to make it so that if a value hasn't been placed in one of the squares that it will show a text area, and if not it will show the value. But I can't get it to work...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>php-tac-toe</title>
</head>
<body>
<strong>php-tac-toe</strong>
<?php
$board=array(array("0","0","0"),array("0","0","0"),array("0","0","0"));
$i=0;
$j=0;
echo "<form action=\"phptactoe.php\" method=\"get\">";
echo "<table border=\"1\">";
$board[0][0]=$_GET['00'];
$board[0][1]=$_GET['01'];
$board[0][2]=$_GET['02'];
$board[1][0]=$_GET['10'];
$board[1][1]=$_GET['11'];
$board[1][2]=$_GET['12'];
$board[2][0]=$_GET['20'];
$board[2][1]=$_GET['21'];
$board[2][2]=$_GET['22'];
for($i=0;$i<3;$i+=1)
{
echo "<tr>";
for($j=0;$j<3;$j+=1)
	{
	echo "<td>";
	if ($board[$i][$j]="0")
		{
		echo "<input name=\""."$i"."$j"."\" type=\"text\" size=\"1\" maxlength=\"1\"/>";
		}
	else
		{
		echo $board[$i][$j];
		}
	echo "</td>";
	}
echo "</tr>";
}
echo "</table>";
echo "<input type=\"submit\" value=\"send\" />";
?>
</body>
</html>

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.