Perad Posted October 20, 2006 Share Posted October 20, 2006 I am tiding up my code and i realised i could use the same script to do 2 functions.On the main page.. [code]$IsLoggedIn = 0[/code]When the user logs in, this is set to 1[code]$IsLoggedIn = 1[/code]I know this works because the post comment area appears and disappears depending if the user is logged in.[code]if ($IsLoggedIn == 1) { /* add a form where users can enter new comments */ echo "<FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\" method=POST>\n"; echo "<p>You are posting as " .$username. "<br />"; echo "<TEXTAREA cols=\"40\" rows=\"5\" " . "name=\"comment\"></TEXTAREA><BR>\n"; echo "<input type=\"submit\" name=\"submit\" " . "value=\"Add Comment\"\n"; echo "</FORM>\n"; } else { echo 'Please log-in to post a comment'; } }[/code]So why doesn't my switch statement work? No matter whether the user is logged in or not, the "else" part is always displayed. Could someone help me fix this please. The switch statement is below. [code] /* this is where the script decides what do do */ if ($IsLoggedIn == 1) { echo "<CENTER>\n"; switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayNews(); } } else { echo "<CENTER>\n"; switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; default: displayNews(); } }[/code]thx Perad Link to comment Share on other sites More sharing options...
vbnullchar Posted October 20, 2006 Share Posted October 20, 2006 try this switch ($_POST['action']) {......} Link to comment Share on other sites More sharing options...
Perad Posted October 20, 2006 Author Share Posted October 20, 2006 Gah, hadn't defined the $IsLoggedIn variable in the function.. Link to comment Share on other sites More sharing options...
Recommended Posts