Undefined index: username

I am getting error when i try to submit my form that is undefined index please help me.

$username = "system";
$password = "Mwasif2001";
$connectionString = "localhost/ORCL";
$conn = oci_connect($username, $password, $connectionString);
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
// username and password sent from form 
$tbl_name = 'USERS';
if(isset($_POST['username']) && isset($_POST['pass']))
    echo ('i am here');
// To protect MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['pass']);
$sql="SELECT * FROM $tbl_name WHERE username='$username'";
echo $sql;
$stid = oci_parse($conn, "SELECT * FROM $tbl_name where username='$username'");
$result = oci_execute($stid);
$count = oci_num_rows($stid);
$stid1 = oci_parse($conn, "SELECT * FROM $tbl_name where user_password='$password'");
$result1 = oci_execute($stid1);
$count1 = oci_num_rows($stid1);
// If result matched $username and $password, table row must be 1 row
if($count == 1 && $count1 == 1)
// Register $username, $password and redirect to file "login_success.php"
$_SESSION["username"] = $username;
else if($count == 0) {
$failed = 1;
else if($count1 == 0) {
$failed = 1;

you have to check every usage of any POST variable before use. and the message is very clear about what is missing (and on which line, if you would have not cut off the message).


1 Like

I am having this output
array (size=0)
what should i do

You’re mixing up two database extensions, are you using a MySQL or an Oracle database? Also any passwords stored in the database should always be in hash form, never in plain text form


what do you mean by hash form i couldnt understand this

Actually i have issue with my post array its empty even after i submit my form


Then show us the html for the form.

Generally you would begin a post form processing script by checking if a post request has been made, like this:-

if($_SERVER['REQUEST_METHOD'] == 'POST') {  // A post request has been made

    // Process the post data from the form

else {    // A post request has not been made

   // Display the html form

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.