post - XAMPP/PHP Undefined Index error -
this question has answer here:
- reference - error mean in php? 29 answers
i'm using xampp php code, set , functional on xampp, but, when open page on browser (google chrome) errors those:
undefined index: logged in c:\xampp\htdocs\teatro\login_teatro.php on line 3 undefined index: admin in c:\xampp\htdocs\teatro\login_teatro.php on line 4 undefined index: btnlogin in c:\xampp\htdocs\teatro\login_teatro.php on line 24 undefined index: logout in c:\xampp\htdocs\teatro\login_teatro.php on line 94 i've used code @ school , works without problems, don't tell me add "isset($_post[])" because not work @ all, don't know why.
hope can me because i'm getting bored of this, i've installed xampp 1.8.1 , removed , reinstalled 1.7.7 version used ad school... not working
<?php session_start(); $_session['logged']; $_session['admin']; ?> <html> <head> <title>login</title> </head> <body> <form action="login_teatro.php" method="post"> <input type="textbox" name="txtuser" value="" placeholder="username"><br> <input type="password" name="txtpsw" value="" placeholder="password"><br> <input type="submit" name="btnlogin" value="login"> <input type="button" name="btnreg" value="registrazione" onclick="window.location='register_teatro.php'"/> </form> <span id="spanresult"></span> </body> <script> document.getelementbyid("spanresult").innerhtml="non sei loggato"; </script> <?php if($_post['btnlogin']) { $conn=mysql_connect("localhost","quintaa","quintaa"); $usr=$_post['txtuser']; $psw=$_post['txtpsw']; mysql_select_db("teatro"); if(!isset($_session['logged'])) { ?> <?php if(isset($_post['btnlogin'])) { if($_post['txtuser']=="" || $_post['txtpsw']=="") { ?> <script> window.alert("alcuni campi richiesti sono vuoti") settimeout("window.location='login_teatro.php'",0); </script> <?php } else { $query="select * persona username='$usr' , password=md5('$psw')"; $rs=mysql_query($query); if(mysql_num_rows($rs)>0) { while(($row=mysql_fetch_assoc($rs))!=null) { $_session['logged']=$usr; /*echo $row['admin'];*/ if($row['admin']==1) { ?> <script> document.getelementbyid('spanresult').innerhtml=""; </script> <?php echo $usr. " sei loggato come amministratore, verrai reindirizzato alla pagina di amministrazione"; $_session['admin']=1; ?> <script>settimeout("window.location='admin_page.php'",2000);</script> <?php } else { echo "sei loggato come ".$usr; } } } } } } else { if(isset($_session['admin'])) { echo $_session['logged']. " sei loggato come amministratore"; ?> <script> settimeout("window.location='admin_page.php'",1500); </script> <?php } else { echo "sei loggato come " .$_session['logged']; } } } if($_post['logout']) { unset($_session ['logged']); unset($_session['admin']); } ?> </html>
generalmente l'errore 'undefined index' è dato quando si cerca di accedere ad un indice di un array associativo che non esiste. ex:
$array['nome'] = "pippo"; se provi stampare la seguente riga
echo $array['nomne']; viene fuori
notice: undefined index: nomne in c:\xampp\htdocs\array\index.php on line 3 hai postato tutto il codice? perchè gli indici incriminati non sono presenti, quindi l'errore apparentemente non ha senso.
Comments
Post a Comment