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

    Whats In Name

    Whats In Name

    @whats-in-name-KdgM7o
    Updated: Oct 26, 2024
    Views: 944
    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:
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorFeb 27, 2013

    #-Link-Snipped-# - 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?
    Are you sure? This action cannot be undone.
    Cancel
  • Whats In Name

    MemberFeb 28, 2013

    The_Big_K
    #-Link-Snipped-# - 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
    {
    ?><script>alert("Invalid Username/Password");</script><?php
    }
    }
    ?>
    <script>
    function validation()
      {
      if(document.login.uname.value=="")
    {
    alert("Please Enter Your Username")
    document.login.uname.focus();
    return false;

    if(document.login.pwd.value=="")
    {
    alert("Please Enter Your Password")
    document.login.pwd.focus();
    return false;
    }
      }
    </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Login</title>
    </head>
    <body>
    <form method="post" name="login" onSubmit="return validation();">
    <table>
      <tr>
        <td>Username</td>
        <td><input type="text" name= "uname" /></td>
      </tr>
      <tr>
        <td>Password</td>
        <td><input type="password" name= "pwd" /></td>
      </tr>
      <tr>
        <td colspan="2"><center><input type="submit" name="sub_login" style="background: url(images/open.gif) no-repeat; width:120px; height:50px; text-indent: -1000em;cursor:pointer;border:none;"/></td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorFeb 28, 2013

    #-Link-Snipped-# , #-Link-Snipped-# - over to you, folks. 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberFeb 28, 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)){
     
     
    }
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberMar 1, 2013

    Change the part:

    $a=@$_REQUEST['uname'];
    $b=@$_REQUEST['pwd'];
    It is a temporary fix only.
    Are you sure? This action cannot be undone.
    Cancel
  • simplycoder

    MemberMar 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.
    Are you sure? This action cannot be undone.
    Cancel
  • Whats In Name

    MemberMar 1, 2013

    @all,Thanks a lot for the replies,they were really informative,
    #-Link-Snipped-#,it solved my problem,thank you.And I will keep it in mind to check for values.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register