-1

Error:

Image of the error

Code:

<?php
  if($_POST['submit']) {
    $ename = $_REQUEST['ename'];
    $civstatus = $_REQUEST['civstatus'];
    $deptno = $_REQUEST['deptno'];
    $hiredate = $_REQUEST['hiredate'];
    $sal = $_REQUEST['sal'];
    $comm = $_REQUEST['comm'];

    include("conn.php");
    $sql = "insert into emp
            (ename,civstatus,
             deptno,hiredate,
             sal,comm) values(
             '$ename','$civstatus',
             '$deptno','$hiredate',
             '$sal','$comm')";
    $res = $conn->query($sql);  
    $conn->close();
  }
?>
Rizier123
  • 58,877
  • 16
  • 101
  • 156

2 Answers2

0

first in your form please check your submit button have name="submit" and in your php code please use isset. try this-

<?php
  if(isset($_POST['submit'])) {
    $ename = $_REQUEST['ename'];
    $civstatus = $_REQUEST['civstatus'];
    $deptno = $_REQUEST['deptno'];
    $hiredate = $_REQUEST['hiredate'];
    $sal = $_REQUEST['sal'];
    $comm = $_REQUEST['comm'];

    include("conn.php");
    $sql = "insert into emp
            (ename,civstatus,
             deptno,hiredate,
             sal,comm) values(
             '$ename','$civstatus',
             '$deptno','$hiredate',
             '$sal','$comm')";
    $res = $conn->query($sql);  
    $conn->close();
  }
?>
shubham715
  • 3,324
  • 1
  • 17
  • 27
0

You need to check name of input elements of all the form fields are same as you are using in php file.

You need to improve your code by checking the values availability like-

<?php
  if(isset($_POST['submit']) {
    $ename = isset($_REQUEST['ename']) ? $_REQUEST['ename'] : '';
    $civstatus = isset($_REQUEST['civstatus']) ? $_REQUEST['civstatus'] : '';
    $deptno = isset($_REQUEST['deptno']) ? $_REQUEST['deptno'] : 0;
    $hiredate = isset($_REQUEST['hiredate']) ? $_REQUEST['hiredate'] : '';
    $sal = isset($_REQUEST['sal']) ? $_REQUEST['sal'] : 0;
    $comm = isset($_REQUEST['comm']) ? $_REQUEST['comm'] : ''; 

    include("conn.php");

    $sql = "insert into emp
            (ename,civstatus,
             deptno,hiredate,
             sal,comm) values(
             $ename,$civstatus,
             $deptno,$hiredate,
             $sal,$comm)";

    $res = $conn->query($sql);  
    $conn->close();
  }
?>

You also need to check conn.php file for any undefined index .

Afshan Shujat
  • 541
  • 4
  • 9