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>&nbsp;</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>&nbsp;</p>
</form>

<p>&nbsp;</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> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Seatnumber&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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);
}
Member Avatar for diafol

YUCK! Use code tags; [ CODE ]

Are we supposed to download 4 files and then analyse them? Obviously, this is your first post. Try again. This is coursework right?

no only tell me that how can i take text field as an array?
actually i search seat numbers due to true three conditions and this is easy to use select and while loop and return these seat numbers in text field but i want to search seat numbers in text fields in onchange event so i am using ajax and it work fine now but now i m again submit these seat numbers with marks so i am using insert query but it was not work so plz tell me that how i take text field as an array and these array how i use in insert query??
suppose this is text field so how can i apply array?
<div id="seatdiv">

<div align="left"><strong>Seat Numbers</strong>

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

</div>
</div>
Member Avatar for diafol

Your post makes no sense to me. Sorry.

If I understand correctly (and that is doubtful considering the length and complexity of your post), you're trying to store an array of data in a text field.

You need to do some database design first.

1. Decide on a maximum number of items (and their amalgamated size) and concatenate them together - using a pipe or some recognizable delimiter. Then write it into your field. Every time you need you'll have to unpack it, update something, repack and store it. This is dumb - but useful if you're in a hurry AND can limit the size of the array.

-OR-

2. Design the database properly, so that you can store the multiple array entries as separate rows in another table linked back to your main table by its Row ID.

~NZS.

Copy this into notepad and save it as a html file:

---------- CUT HERE ----------------------------------------…

<P><INPUT TYPE=TEXT VALUE="Your Name">
<BR><INPUT TYPE=TEXT VALUE="Address">
<BR><INPUT TYPE=TEXT VALUE="Phone">
best r4 card
<BR><INPUT TYPE=TEXT VALUE="Email">
<BR><INPUT TYPE=RADIO NAME=S> Male
<BR><INPUT TYPE=RADIO NAME=S> Female

<BR><BR>
<INPUT TYPE=SUBMIT VALUE="Sing up">
<BR><FONT COLOR=RED>

cheap r4 card


<SCRIPT>

for (i = 0; i < 20; i++)
{
document.write(" <BR> document.all[" + i +"] = " + document.all.value);
}
buy r4i card
// We will now update the value of the first text box...
document.all[5].value = "Linda";

</SCRIPT>

thanks but actully this is not solution of my problem.
firstly i want to search seat numbers/roll numbers of Pharm.D students in text fields.
for e.g:pharm.d seat numbers in mysql db 4 seat numbers then search in search in 4 text fields.
secondly insert these seat numbers with different marks(mid, lab, terminal marks) in another table.
iam facing problem in insert query, i don't understand that how can i call different text field of seat numbers. im using following insert query now tell me how can i take 2nd,3rd,4th seat numbers in insert query.
in mysql db have different degrees and different degrees have different seat number
one solution is that i call seat1, seat2,seat3 and seat4 but i want to know general solution.

$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')";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.