how can i insert values of text fields values in mysql db i m using php mysql and ajax
ajax to search seat numbers bases of batch, degree and semester this search successful but it cannot insert another table may be using array using this field so how i use array as an text field in insert query??
problem part of my project
enter_marks.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="mystyle.css" rel="stylesheet" type="text/css">
<script language="javascript" src="enter_marks.js"></script>
</head>
<body>
<h1>Enter Marks Of Students</h1>
<form name="fm" action="enter_marks.php" method="get" >
<table width="288" border="0">
<tr><td width="290">
<div align="left"><strong>Teacher</strong> :
<select name="teacher" onChange="getCourse(this.value);getCourse(document.fm.teacher.selectedIndex);">
<option value="">Select Teachers</option>
<option value="Dr. Husan Afroze Rizvi">Dr. Husan Afroze Rizvi</option>
<option value="Ms. Talat Syeda">Ms. Talat Syeda</option>
<option value="Ms. Farah Tariq">Ms. Farah Tariq</option>
<option value="Dr. Afshan Wasti">MDr. Afshan Wasti</option>
<option value="Ms. Farah Jabeen">Ms. Farah Jabeen</option>
</select>
<br />
</div>
</td></tr><tr><td>
<div id="coursediv">
<div align="left"><strong>Course Number</strong>:
<select name="course" id="course">
<option>Select courses</option>
</select>
</div>
</div>
</td></tr><tr><td>
<div align="left"><strong>Department</strong> :
<select name="dept" onChange="getDegree(this.value);getDegree(document.fm.dept.selectedIndex);">
<option value="">Select Department</option>
<option value="Biochemistry">Biochemistry</option>
<option value="Botany">Botany</option>
<option value="Business Administration">Business Administration</option>
<option value="Chemistry">Chemistry</option>
<option value="Commerce">Commerce</option>
<option value="Computer Science & IT">Computer Science & IT</option>
</select>
<br />
</div></td></tr><tr><td>
<div align="left"><strong>Degree</strong> :
<select name="degree" onChange="getSeat(this.value,this.value,this.value);getSeat(document.fm.degree.selectedIndex,document.fm.batch.selectedIndex,document.fm.semester.selectedIndex);">
<option value="">Select degree</option>
<option value="BS(Hons) Biochemistry">BS(Hons) Biochemistry</option>
<option value="Biochemistry">Biochemistry</option>
<option value="BS(Hons) Botany">BS(Hons) Botany</option>
<option value="MSc. Botany">MSc. Botany</option>
<option value="BBA(Honors)">BBA(Honors)</option>
<option value="MBA">MBA</option>
<option value="BS(Hons) Chemistry">BS(Hons) Chemistry</option>
<option value="MSc. Chemistry">MSc. Chemistry</option>
<option value="B.Com (Honors)">B.Com (Honors)</option>
<option value="M.Com">M.Com</option>
<option value="B.S (Computer Science)">B.S (Computer Science)</option>
<option value="B.S (Information Technology)">B.S (Information Technology)</option>
<option value="B.S (Electronics)">B.S (Electronics)</option>
<option value="BCS">BCS</option>
<option value="MS (Software Engineering)">MS (Software Engineering)</option>
</select>
<br />
</div></td></tr><tr><td>
<div align="left"><strong>Batch</strong> :
<select name="batch" onChange="getSeat(this.value,this.value,this.value);getSeat(document.fm.degree.selectedIndex,document.fm.batch.selectedIndex,document.fm.semester.selectedIndex);">
<option value="">Select Batch</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
</select>
<br />
</div></td></tr><tr><td>
<div align="left"><strong>Semester</strong> :
<select name="semester" onChange="getSeat(this.value,this.value,this.value);getSeat(document.fm.degree.selectedIndex,document.fm.batch.selectedIndex,document.fm.semester.selectedIndex);">
<option value="">Select Semester</option>
<option value="first">first</option>
<option value="second">second</option>
<option value="third">third</option>
<option value="fourth">fourth</option>
<option value="fifth">fifth</option>
<option value="six">six</option>
<option value="seventh">seventh</option>
<option value="eighth">eighth</option>
</select>
<br />
</div></td></tr>
</table>
<p> </p>
<table width="614" border="3" >
<tr>
<td><div id="seatdiv">
<div align="left"><strong>Seat Numbers</strong>
<input name="seat" type="text" id="seat"/ >
<input name="mid" type="text" id="mid"/ >
<input name="lab" type="text" id="lab"/ >
<input name="terminal" type="text" id="terminal"/ >
</div>
</div></td>
</tr>
<tr>
<td height="26" colspan="4"><input type="submit" name="Submit" value="Submit" onClick="getCourse(str); getSeat(str,cat,par)"></td>
</tr>
</table>
<p> </p>
</form>
<p> </p>
</body>
</html>
<?php
if (!empty($_GET['seat']))
{
$a=$_GET['mid'];
$b=$_GET['lab'];
$c=$_GET['terminal'];
$total=$a+$b+$c;
$d;
if($total<50)
{
$d="fail";
}
else
{
$d="pass";
}
$per=($total)*100/100;
if($per>=90)
{
$grade="A+";
$gp=4.0;
}
elseif($per>=85 && $per<=89)
{
$grade="A";
$gp=4.0;
}
elseif($per>=80 && $per<=84)
{
$grade="A-";
$gp=3.8;
}
elseif($per>=75 && $per<=79)
{
$grade="B+";
$gp=3.4;
}
elseif($per>=71 && $per<=74)
{
$grade="B";
$gp=3.0;
}
elseif($per>=68 && $per<=70)
{
$grade="B-";
$gp=2.8;
}
elseif($per>=64 && $per<=67)
{
$grade="C+";
$gp=2.4;
}
elseif($per>=61 && $per<=63)
{
$grade="C";
$gp=2.0;
}
elseif($per>=57 && $per<=60)
{
$grade="C-";
$gp=1.8;
}
elseif($per>=53 && $per<=56)
{
$grade="D+";
$gp=1.4;
}
elseif($per>=50 && $per<=52)
{
$grade="D";
$gp=1.0;
}
else
{
$grade="F";
$gp=0.0;
}
//$per=($*100)/100;
if (!empty($_POST['teacher']))
{
if($search=mysql_query("select Seat_Number from student_enroll where Batch='$_GET[batch]' and Semester='$_GET[semester]' and Degree='$_GET[degree]'"))
{
while($row=mysql_fetch_array($search))
{
$insert="insert into enter_marks_teacher (Full_Name,Course_Number,Dept_Name,Degree,Batch,Semester,Seat_Number,Mid,Lab,Terminal,Total,Remarks,Percentage,Grade,CGPR) values('$_GET[teacher]','$_GET[course]','$_GET[dept]','$_GET[degree]','$_GET[batch]','$_GET[semester]','$_GET[seat]','$_GET[mid]','$_GET[lab]','$_GET[terminal]','$total','$d','$per','$grade','$gp')";
include_once("connect.php");
if(!mysql_query($insert))
{
die('error in insert query');
}
else
{
echo("1 Record added");
}
}
}
}
}
?>
findseatno.php
<head>
<link href="mystyle.css" rel="stylesheet" type="text/css">
</head>
<?php
$name=$_GET["batch"];
$name2=$_GET["semester"];
$name3=$_GET["degree"];
$link = mysql_connect("localhost","root",""); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("result_system_db",$link);
if($search=mysql_query("select Seat_Number from student_enroll where Batch_Id=$name and Semester_Id=$name2 and Degree_Id=$name3"))
{
echo "<b> Seatnumber </b><br/>";
echo "<input name='seat' type='hidden'>";
echo "<input name='mid' type='hidden'>";
echo "<input name='lab' type='hidden'>";
echo "<input name='terminal' type='hidden'>";
while($row=mysql_fetch_array($search))
{
echo "<td><input name='seat' id='seat' type='text' value=".$row['Seat_Number']."></td>";
echo "<td><input name='seat' id='mid' type='text' ></td>";
echo "<td><input name='seat' id='lab' type='text' ></td>";
echo "<td><input name='seat' id='terminal' type='text' ></td></br>";
}
echo "</input>";
echo "</input>";
echo "</input>";
echo "</input>";
}
else
echo "error";
mysql_close($link);
?>
enter_marks.js
function getCourse(str)
{
if (str=="")
{
document.getElementById("coursediv").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("coursediv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","findcourse.php?teacher="+str,true);
xmlhttp.send("course=" + document.getElementById("course").value);
}
function getSeat(str,cat,par)
{
if (str=="")
{
document.getElementById("seatdiv").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("seatdiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","findseatno.php?degree="+str+"&batch="+cat+"&semester="+par,true);
xmlhttp.send("seat=" + document.getElementById("seat").value);
}