tinfanide Posted August 15, 2011 Share Posted August 15, 2011 ( ! ) Notice: Undefined index: lang in C:\wamp\www\LanguageChooser.php on line 3 Call Stack # Time Memory Function Location 1 0.0001 368384 {main}( ) ..\LanguageChooser.php:0 I tried the php codes below but I've got the above error message on both IE8 and Firefox 4.I followed a Youtube PHP tutorial:PHP tutorial on YoutubeHe didn't encounter such an error message but I did.How could I fix the error? I don't ever know what kind of php errors it is. <?php$lang = $_POST['lang'];?><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><form action="LanguageChooser.php" method="POST">Language:<select name="lang"><option value="English" <?php if($lang=="English"){echo "SELECTED";} ?> >English</option><option value="French" <?php if($lang=="French"){echo "SELECTED";} ?> >française</option></select><input type="submit" name="submit" value="Choose" /></form></body></html><?php switch ($lang){ case "English": include "lang/english.php"; break; case "French"; include "lang/french.php"; break; default: include "lang/english.php"; break; }echo $first."<br />";echo $second;?> Link to comment Share on other sites More sharing options...
tinfanide Posted August 15, 2011 Author Share Posted August 15, 2011 Actually I've just found an answer to this online:He suggested three ways:1. Initialize every variable before using. In my case, I think it may be like: $lang = ""; 2. Change your php.ini file and set error_reporting to the following. error_reporting = E_ALL & ~E_NOTICE This will show all the errors except notices.3. Add this line in your script. This is a runtime setting to show all errors except notices. <?php error_reporting(E_ALL & ~E_NOTICE); //your code here ?> But I failed with the first one.For the second and third ones, it seems not a workaround. Seems like just skipping the notice.So I wanna ask if that error matters in php scripting? Cos I do not have problems with the php page even the php error exists. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 15, 2011 Share Posted August 15, 2011 The correct fix looks like this:$lang = isset($_POST['lang']) ? $_POST['lang'] : '';That will only access $_POST['lang'] if it is set. The error is because $_POST['lang'] is not set and you're trying to read it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.