Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax and PHP - Error in Insertion
    primarykey
    data
    text
    <p>Im using Ajax to get a value from the Drop down box and display the result .Example, Im having three types of mess in drop down box (veg,non veg and senior mess). Here is my code from Sql part:</p> <pre><code>&lt;?php $q=$_GET["q"]; $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("hostel", $con); $sql="SELECT registration.hosteladmissionno,registration.student_name,registration.semester,messexp.billmonth,messexp.billyear,messexp.wastagecharge,exp_amount.blockexp FROM registration,messexp,blockexp WHERE registration.mess_type = '".$q."' &amp;&amp; status_flag=1"; $result = mysql_query($sql); echo "&lt;table border='1' width=80%&gt; &lt;tr&gt; &lt;th width=5%&gt; S.No&lt;/th&gt; &lt;th width=10%&gt;H.Admin No&lt;/th&gt; &lt;th width=10%&gt;Student Name&lt;/th&gt; &lt;th width=10%&gt;Semester&lt;/th&gt; &lt;th width=10%&gt;Billmonth&lt;/th&gt; &lt;th width=10%&gt;Bill Year&lt;/th&gt; &lt;th width=10%&gt;Wastage Charge&lt;/th&gt; &lt;th width=10%&gt;Block Amount&lt;/th&gt; &lt;th width=5%&gt;No of Days&lt;/th&gt; &lt;/tr&gt;"; $i=0; while($row = mysql_fetch_array($result)) { $i=$i+1; echo "&lt;tr&gt;"; echo "&lt;td align=center&gt;" .$i."&lt;/td&gt;"; echo "&lt;td size=10 align=center&gt;" . $row['hosteladmissionno'] . "&lt;/td&gt;"; echo "&lt;td size=35 align=center&gt;" . $row['student_name'] . "&lt;/td&gt;"; echo "&lt;td size=10 align=center&gt;" . $row['semester'] . "&lt;/td&gt;"; echo "&lt;td size=35 align=center&gt;" . $row['billmonth'] . "&lt;/td&gt;"; echo "&lt;td size=10 align=center&gt;" . $row['billyear'] . "&lt;/td&gt;"; echo "&lt;td size=35 align=center&gt;" . $row['wastagecharge'] . "&lt;/td&gt;"; echo "&lt;td size=35 align=center&gt;" . $row['exp_amount'] . "&lt;/td&gt;"; echo "&lt;td align=center&gt; &lt;input type='text' name='days' size=2&gt; &lt;/td&gt; "; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysql_close($con); ?&gt; </code></pre> <p>Ajax Part:</p> <pre><code> &lt;script type="text/javascript"&gt; function showUser(str) { if (str=="") { document.getElementById("txtHint").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 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","messbill1.php?q="+str,true); xmlhttp.send(); } &lt;/script&gt; </code></pre> <p>From this I wanna insert The displayed details while we select the mess. how do i do the insert query. The field names are from different Tables.</p> <p>Forms part: </p> <pre><code> &lt;h2 align='center'&gt;&lt;b&gt;Mess Bill&lt;/h1&gt;&lt;/b&gt; &lt;form action="messbill.php" onchange="showUser(this.value)"/&gt; &lt;center&gt; &lt;table&gt; &lt;?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("hostel",$link); $query = "SELECT mess_type FROM mess_type"; $result = mysql_query($query); print "&lt;tr&gt;&lt;td&gt;&lt;b&gt;MESS TYPE:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;SELECT name='users' onchange='showUser(this.value)'&gt;"; while ($line = mysql_fetch_array($result)) { foreach ($line as $value) { print "&lt;OPTION value='$value'"; } print "&gt;$value&lt;/OPTION&gt;"; } mysql_close($link); print "&lt;/SELECT&gt;&lt;/td&gt;&lt;/tr&gt;"; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload