Lumit Posted June 4, 2008 Share Posted June 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
Lautarox Posted June 4, 2008 Share Posted June 4, 2008 It depends on the script you'r using, if you'r using get for including pages, and you get blank the var you have chosen, it won't do anything unless you program it. Quote Link to comment Share on other sites More sharing options...
btherl Posted June 5, 2008 Share Posted June 5, 2008 The full details are here: http://www.php.net/manual/en/types.comparisons.php But the short answer is that you can use isset() to see if a variable is set or not. If isset() returns false, then the variable was not passed in. Quote Link to comment Share on other sites More sharing options...
haku Posted June 5, 2008 Share Posted June 5, 2008 If you have: http://www.example.com/page.php?cat Then $_GET['cat'] is set, but empty. Basically the following is true: $_GET['cat'] == "" If you have: http://www.example.com/page.php Then $_GET['cat'] is not set, and the following will be true: isset($_GET['cat']) == false Quote Link to comment Share on other sites More sharing options...
btherl Posted June 5, 2008 Share Posted June 5, 2008 $_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. Quote Link to comment Share on other sites More sharing options...
Lumit Posted June 5, 2008 Author Share Posted June 5, 2008 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> Quote Link to comment Share on other sites More sharing options...
btherl Posted June 7, 2008 Share Posted June 7, 2008 This line if ($board[$i][$j]="0") should be this: if ($board[$i][$j] == "0") One reason for leaving a space around the "==" is that it's easier to see whether it's == or = Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.