I am new in php and in this registration form I am getting the following error in following code.:
1. Notice: Undefined index: gender..
2. Notice: Array to string conversion in the line of mysql query...
I have given name to radio button still it is showing undefined index. and second one is array to string conversion in mysql query i am not able to understand what's going wrong. please help me and thank u in advance.
<?php
include_once 'conn.inc';
if(isset($_POST['btnsave']))
{
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 40000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
$_SESSION['image']=$_FILES["file"]["name"];
}
}
else {
echo "fail";
}
$name=$_POST['txtname'];
$fname=$_POST['txtfname'];
$gender=$_POST['gender'];
$image=$_FILES['file'];
$des=$_POST['designation'];
$job=$_POST['txtjob'];
$country=$_POST['txtcont'];
$state=$_POST['txtstate'];
$city=$_POST['txtcity'];
$email=$_POST['txtemail'];
$csatuts=$_POST['contactno'];
$esatuts=$_POST['email'];
$contact=$_POST['txtno'];
$query="insert into tblregistration values('','$name','$fname','$gender','$image','$des','$job','$country','$state','$city','$contact','$csatuts','$email','$esatuts') " or die('error');
$res= mysql_query($query);
if(mysql_affected_rows())
{
$e= "You are successfully registered!!!";
}
}
?>
HTML part
<div id="content">
<div class="box"><div class="heading">Registration</div></div>
<div class="reg">
<form action="registration.php" method="post" enctype="multipart/form-data">
<table cellpadding="5px" cellspacing="5px">
<tr>
<td><label for="txtname">Name</label></td>
<td><input type="text" name="txtname" value="Enter your name" class="tb22"/></td>
</tr>
<tr>
<td><label for="txtfname">Father's Name</label></td>
<td><input type="text" name="txtfname" value="Enter your father's name" class="tb22" /></td>
</tr>
<tr>
<td><label>Gender</label></td>
<td>Male<input type="radio" name="gender" value="m"/>
Female<input type="radio" name="gender" value="f" /></td>
</tr>
<tr>
<td>
<input onchange="readURL(this);" type="file" name="file" /></td>
<td><img alt="Image Display Here" id="test" src="./upload/icon3.jpg" height="100px" width="100px" /></td>
</tr>
<tr>
<td><label>Designation</label></td>
<td><select name="designation" class="tb22">
<option value="-1">Select Designation</option>
<option value="employed">Employed</option>
<option value="selfemployed">Self-Employed</option>
<option value="Retired">Retired</option>
</select></td>
</tr>
<tr>
<td><label for="txtjob">Title of JOB</label></td>
<td><input type="text" name="txtjob" value="Title of job" class="tb22" /></td>
</tr>
<tr>
<td><label for="txtcont">Country</label></td>
<td><input type="text" name="txtcont" class="tb22" value="Enter your Country"/></td>
</tr>
<tr>
<td><label for="txtstate">State</label></td>
<td><input type="text" name="txtstate" value="Enter your state" class="tb22"/></td>
</tr>
<tr>
<td><label for="txtcity">City</label></td>
<td><input type="text" name="txtcity" value="Enter your city" class="tb22"/></td>
</tr>
<tr>
<td><label for="txtno">Contact No.</label></td>
<td><input type="number" name="txtno" value="Enter your no." class="tb22" /> <i>private</i> <input type="radio" name="contactno" value="0" /> <i>public</i> <input type="radio" name="contactno" value="1" /></td>
</tr>
<tr>
<td><label for="txtemail">Email</label></td>
<td><input type="email" name="txtemail" value="Enter your email" class="tb22" /> <i>private</i> <input type="radio" name="email" value="0" /> <i>public</i> <input type="radio" name="email" value="1" /></td></td>
</tr>
</table>
<input type="submit" name="btnsave" value="submit" class="tb20" />
<?php if(isset($e))
{ echo "$e";}
?>
</form>