View Feed
group-icon
PHP Programmers
Community for PHP Programmers : Ask questions, doubts and help each other get better at PHP
297 Members
Join this group to post and comment.
Whats In Name
Whats In Name • Feb 28, 2013

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

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:
Kaustubh Katdare
Kaustubh Katdare • Feb 28, 2013
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
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
Praveen-Kumar , simplycoder - over to you, folks. 😀
Manish Goyal
Manish Goyal • Mar 1, 2013
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)){
 
 
}
Change the part:

$a=@$_REQUEST['uname'];
$b=@$_REQUEST['pwd'];
It is a temporary fix only.
simplycoder
simplycoder • Mar 1, 2013
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
@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.

Share this content on your social channels -