1. Home >
  2. Apps >
  3. Groups >

PHP:Why I get notice when running in Xampp server?

Question asked by Whats In Name in #PHP on Feb 28, 2013
Whats In Name
Whats In Name · Feb 28, 2013
Rank B3 - LEADER
When I run a code in wamp server it displays output but when I run the same code in Xampp server why it shows so many notices(with output) like-
Notice:Undefined index:
Posted in: #PHP
Kaustubh Katdare
Kaustubh Katdare · Feb 28, 2013
Rank A1 - PRO
Whats In Name - Two things -

1. Is that the full error message? Is there any detail included after Undefined index:.. ?
2. Possible for you to post the code so that experts here can dig deeper?
Whats In Name
Whats In Name · Feb 28, 2013
Rank B3 - LEADER
The_Big_K
Whats In Name - Two things -

1. Is that the full error message? Is there any detail included after Undefined index:.. ?
2. Possible for you to post the code so that experts here can dig deeper?

Actually,here's the full message-

Notice: Undefined index: uname in C:\xampp\htdocs\project\login.php on line 5

Notice: Undefined index: pwd in C:\xampp\htdocs\project\login.php on line 6

and code-
php
session_start
();
include(
"connection.php");
ob_start();
$a=$_REQUEST['uname'];
$b=$_REQUEST['pwd'];
if(isset(
$_REQUEST['sub_login']))
{
$query="select * from register where uname='$a' and pwd='$b'";
$queryexe=mysql_query($query);
$count=mysql_num_rows($queryexe);
$row=mysql_fetch_array($queryexe);
$id=$row['user_id'];
$_SESSION['user_id']=$id;
if(
$count>0)
{
header("location:profile.php");
}
else
{
?>}
}
?>





Login




  
    
    
  
  
    
    
  
  
    

  

Username
Password



Kaustubh Katdare
Kaustubh Katdare · Feb 28, 2013
Rank A1 - PRO
Praveen-Kumar , simplycoder - over to you, folks. 😀
Manish Goyal
Manish Goyal · Mar 1, 2013
Rank A2 - PRO
That's a bad coding art, you must check if there is any data in $_REQUEST or not assuming uname and pwd will always be present in data, if not then check isset($_REQUEST['uname'])

if(!empty($_REQUEST)){
 
 
}
PraveenKumar Purushothaman
Rank A1 - PRO
Change the part:

$a=@$_REQUEST['uname'];
$b=@$_REQUEST['pwd'];
It is a temporary fix only.
simplycoder
simplycoder · Mar 1, 2013
Rank B3 - LEADER
I agree with goyal, never assume that the program would behave the way you think it will be.
When a developer develops something, he/she performs unit testing without much of destructive cases(a happy flow), but ideally this is a bad and a wrong practice to assume. Always check for values, same applies when session variables are being stored or retrieved.
Whats In Name
Whats In Name · Mar 1, 2013
Rank B3 - LEADER
@all,Thanks a lot for the replies,they were really informative,
goyal420,it solved my problem,thank you.And I will keep it in mind to check for values.

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up