<form action="forum get.php" method="post"> <input type="text" name="id"> <input type="password" name="pass"> <input type="submit" value="Login"> </form> <?php $a=$_POST["id"]; $b=$_POST["pass"]; echo $a.$b; ?> Here is my simple code, it always echo values but with error "undefine index on 1 and 2 in php code". i have also tried get, request method aswell, but still i get the error. plz help me out, give me a solution.
There's wrong action in the form "forum get.php". for testing you can use something like this: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="text" name="id"> <input type="password" name="pass"> <input type="submit" value="Login"> </form> <?php if ( count($_POST) > 0 ) { $a=$_POST["id"]; $b=$_POST["pass"]; echo $a.$b; } ?> Code (markup):
Either you give the forum inputs preset values of empty, value="" or check if id & pass are set before you assign them to variables. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="text" name="id" value=""> <input type="password" name="pass" value=""> <input type="submit" value="Login"> </form> <?php $a = $b = ''; if (isset($_POST['id'])) { $a=$_POST["id"]; } if (isset($_POST['pass'])) { $b=$_POST["pass"]; } echo $a.$b; PHP:
The script works as it is however you have your error_reporting on high undefined index is just a warning so yes you can use what Joker-jar and ThePHPMaster have said to get rid of the error or you can just change your error reporting level by using hte error_reporting function http://www.php.net/manual/en/function.error-reporting.php