0

this is my code for inserting records into my form which is in html file
Inline Code Example Here

<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$connect=mysql_connect("localhost","root","") or die(mysql_error());
$db_select=mysql_select_db("employee",$connect) or die(mysql_error());

if (isset($_POST['id'])) 

$id=$_POST['id'];
if (isset($_POST['name'])) 
$name=$_POST['name'];
if (isset($_POST['gender'])) 
$gender=$_POST['gender'];
if (isset($_POST['mobile'])) 
$mobile=$_POST['mobile'];
if (isset($_POST['email'])) 
$email=$_POST['email'];
$qry="insert into emp(id,name,gender,mobile,email) values ('$id','$name','$gender',$mobile,'$email')";
$result=mysql_query($qry)  or die(mysql_error());

if($result)
{
echo "DETAILS ADDED SUCCESSFULLY";
}
else
{
echo "TRY AGAIN";
}

?>
3
Contributors
4
Replies
13
Views
3 Years
Discussion Span
Last Post by hiiiiii@
0

undefined index means you tried to access an array position that didn't exist. E.g. $array[10] when $array only has five elements. Associative arrays have the same problem e.g. trying to get $array['bob'] when that isn't in the array.

Which lines is giving the error? At a glance your code looks OK

0

thanks

this is my html file for form
<html>
<title> EMPLOYE DETAILS</title>

<body>

<fieldset style=text-align:left>
<form name=empdetails id=empdetails action=page2.php method=POST>

 ID : <input type=text id=id name=id ><br>

 NAME :<input type=text id=name name=name ><br>
 GENDER :
<input type=radio id=gender name=gender value=f>FEMALE<br>
 <input type=radio  id=gender1 name=gender value=m> MALE<br>
MOBILE NO <input type=text id=mobile name=mobile ><br>
EMAIL ID <input type=email id=email name=email >
<br>
 <input type=submit id=submit name=submit><br>
 </form>
<form name=empdetails id=empdetails action=page3.php>
  <input type=submit id=submit name=view value=view ><br>

 </form>
 <form name=empdetails id=empdetails action=page4.php>
  <input type=submit id=submit name=view value=UPDATE ><br>

 </form>
  <form name=empdetails id=empdetails action=page5.php>
  <input type=submit id=submit name=view value=DELETE ><br>

 </form>

</body>

</html>


my php code for insert

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

$connect=mysql_connect("localhost","root","") ;

$db_select=mysql_select_db("employee",$connect) ;
  if (isset($_POST['id']) && isset($_POST['name']) && isset($_POST['gender']) && isset($_POST['mobile']) &&isset($_POST['email']));
{

$id=$_POST['id'];

$name=$_POST['name'];

$gender=$_POST['gender'];

$mobile=$_POST['mobile'];

$email=$_POST['email'];

$qry="insert into emp(id,name,gender,mobile,email) values('$id', '$name', '$gender','$mobile','$email')";
$result=mysql_query($qry) or die(mysql_error());

if($result)
{
echo "DETAILS ADDED SUCCESSFULLY";
}
else
{
echo "TRY AGAIN";
}
}
?>
 im geting undefined index error for all my variable ($id,$name,$gender,$mobile,$email)
 my database structure is 
 +--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | varchar(5)  | NO   | PRI | NULL    |       |
| name   | varchar(25) | NO   |     | NULL    |       |
| gender | varchar(1)  | NO   |     | NULL    |       |
| mobile | int(10)     | NO   |     | NULL    |       |
| email  | varchar(25) | NO   |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+

i tried in many ways but it is showing undeifed index error when i use post method .i checked with request method it is acceting value .
0

how come your html doesn't have double quotes "" or singel quotes '' ?

<input type="text" id="name" name="name" >

or did u just omit them for this post?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.