javascript - Form submits, inserts data to database but does not then display contents in div -
i have div form in it. when form submitted want data inserted database , results database displayed form underneath can submitted again record added. form submitting , database being populated results not display in div.
the div contains inital form (and contain refreshed results list , new form follows:
<div id=activitylist> <? $q2a="select activitynumber, title, description, leaders, time activities activities.meetingid='$id' , activities.unitid='$input2'"; $r2a=mysqli_query($dbc,$q2a) or die(mysqli_error($dbc)); echo "<table class='layouttable'><tr><td>activitynumber</td><td>title</td><td>description</td><td>leaders</td><td>time</td><td>edit</td>"; while($row2a =mysqli_fetch_assoc($r2a)) { echo " <tr><td>" . $row2a['activitynumber'] . "</td> <td>" . $row2a['title'] . " </td> <td>" . $row2a['description'] . " </td> <td>" . $row2a['leaders'] . " </td> <td>" . $row2a['time'] . " </td> <td><input type='button' value='editactivity' onclick='editactivity(" . $row2a['activityid'] . ")'></td></tr>. "; } echo"</table>"; ?><br><br> <form id='newactivity' method="post" onsubmit="return submitform();"> <input type =hidden name='meetingid' value=<?echo$id?>> <b>activity number:</b><input type=text name='activitynumber' class='textborder'> <b>title:</b><input type=text name='activitytitle' class='textborder'> <b>time (mins):</b> <input type=text name='activitytime' class='textborder'> <b>leaders:</b> <input type=text name='leaders' class='textborder'><br> <b>description:</b><textarea name='activitydescription' class='textareaborder'></textarea> <input type='submit' value='submit'></form></div>
the form submitted using:
<script name='addactivity'> function submitform() { $.ajax({type:'post', url: 'activity_new.php', data:$('#newactivity').serialize(), success: function(response) { $('#newactivity').find(".activitylist").html(response); }}); return false; } </script>
and activity_new.php inserting database , want display in div when has done insert is:
<?php session_start(); $input2=$_session[ 'unitid' ]; $meetingid=$_post['meetingid']; $activitynumber=$_post['activitynumber']; $activitytitle=$_post['activitytitle']; $activitytime=$_post['activitytime']; $leaders=$_post['leaders']; $activitydescription=$_post['activitydescription']; include 'connect_db.php'; $q1c="insert activities (meetingid, unitid, activitynumber, title, description, time, leaders) values ('$meetingid', '$input2', '$activitynumber','$activitytitle', '$activitydescription', '$activitytime', '$leaders')"; $r1c = mysqli_query($dbc,$q1c)or die(mysqli_error($dbc)); $q2a="select activitynumber, title, description, leaders, time activities activities.meetingid='$meetingid' , activities.unitid='$input2'"; $r2a=mysqli_query($dbc,$q2a) or die(mysqli_error($dbc)); echo "<table class='layouttable'><tr><td>activitynumber</td><td>title</td><td>description</td><td>leaders</td><td>time</td><td>edit</td>"; while($row2a =mysqli_fetch_assoc($r2a)) { echo " <tr><td>" . $row2a['activitynumber'] . "</td> <td>" . $row2a['title'] . " </td> <td>" . $row2a['description'] . " </td> <td>" . $row2a['leaders'] . " </td> <td>" . $row2a['time'] . " </td> <td><input type='button' value='editactivity' onclick='editactivity(" . $row2a['activityid'] . ")'></td></tr>. "; }; echo"</table>"; ?><br><br> <form id='newactivity' method="post" onsubmit="return submitform();"> <input type =hidden name='meetingid' value=<?echo$id?>> <b>activity number:</b><input type=text name='activitynumber' class='textborder'> <b>title:</b><input type=text name='activitytitle' class='textborder'> <b>time (mins):</b> <input type=text name='activitytime' class='textborder'> <b>leaders:</b> <input type=text name='leaders' class='textborder'><br> <b>description:</b><textarea name='activitydescription' class='textareaborder'></textarea> <input type='submit' value='submit'>
edit jquery selector id selector div has id not class. omit #newactivity ! not parent of activitylist child. enough:
$("#activitylist").html(response);