php - Submitting multiple forms to database one by one -
my code fetches entries database , prints them separate forms accept or deny each of them using buttons of different actions. whenever perform action on 1 of forms, not operation on same form instead moves order starting first entry in database.
in picture above, if accepted second form, perform function on first form.
code:
<?php } else if ($usertype == 1) { ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); $server = ""; $user = ""; $pass = "r=~"; $db = ""; $db3 = "aukwizcq_professors"; $user1 = $_session['username']; $mysqli = new mysqli($server, $user, $pass, $db) or mysqli_error($mysqli); $mysqli5 = new mysqli($server, $user, $pass, $db3) or mysqli_error($mysqli); $name= $mysqli5->query("select name professor username= '$user1'")->fetch_object()->name; //taking name list of professors equal userid logged in (if hes professor, show, if not 0) $overrides = $mysqli->query("select * overrides professor= '$name' , status ='1'"); $num_rows = mysqli_num_rows($overrides); echo " pending overrides: " . $num_rows; ?> <?php while($row = mysqli_fetch_array($overrides)) { ?> <fieldset> <form method="post" action="dbheads.php" name="hf" id="hf" autocomplete="off"> <?php echo "first name: " . $row['name'] . "<br />"; echo "<br />mid. name: " . $row['mname'] . "<br />"; echo "<br />fam. name: " . $row['fname'] . "<br />"; echo "<br />student id: " . $row['sid'] . "<br />"; echo "<br />scolarship: " . $row['sc'] . "<br />"; echo "<br />phone no: " . $row['phone'] . "<br />"; echo "<br />email: " . $row['email'] . "<br />"; echo "<br />subject: " . $row['subject'] . "<br />"; echo "<br />section: " . $row['section'] . "<br />"; echo "<br />semester: " . $row['semester'] . "<br />"; echo "<br />professor: " . $row['professor'] . "<br />"; $id = $row['id']; echo "<input type='hidden' name='id' value='$id'>"; $name = $row['name']; echo "<input type='hidden' name='name' value='$name'>"; $mname = $row['mname']; echo "<input type='hidden' name='mname' value='$mname'>"; $fname = $row['fname']; echo "<input type='hidden' name='fname' value='$fname'>"; $sid = $row['sid']; echo "<input type='hidden' name='sid' value='$sid'>"; $sc = $row['sc']; echo "<input type='hidden' name='sc' value='$sc'>"; $phone = $row['phone']; echo "<input type='hidden' name='phone' value='$phone'>"; $email = $row['email']; echo "<input type='hidden' name='email' value='$email'>"; $subject = $row['subject']; echo "<input type='hidden' name='subject' value='$subject'>"; $section = $row['section']; echo "<input type='hidden' name='section' value='$section'>"; $semester = $row['semester']; echo "<input type='hidden' name='semester' value='$semester'>"; //$professor = $row['professor']; // echo "<input type='hidden' name='professor' value='$professor'>"; ?> <br /> <div> <label for="comments" accesskey="c">notes & comments:</label><br /> <textarea name="comments" id="comments" cols="50" rows="5"></textarea> <br> </div> <br> <script type="text/javascript"> function submitform(action) { document.getelementbyid('hf').action = action; document.getelementbyid('hf').submit(); } </script> <input type="button" onclick="submitform('dbheads.php')" value="accept" /> <input type="button" onclick="submitform('dbheads2.php')" value="deny" /> </form> </fieldset> <br> <?php } ?>
dbheads.php
<?php include_once 'includes/db_connect.php'; include_once 'includes/functions.php'; sec_session_start(); ?> <html> <?php $mysql_host = "localhost"; $mysql_username = ""; $mysql_password = ""; $mysql_database = ""; $user = $_session['username']; if (login_check($mysqli) == true) : ?> <p>welcome <?php echo htmlentities($user); ?>!</p> <?php $mysqli = new mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database) or die(mysqli_error()); $status = 2; $id = $_post['id']; $stmt = $mysqli->prepare("update overrides set status=? id='$id'"); $stmt->bind_param("s", $status); $stmt->execute(); print 'error : ('. $mysqli->errno .') '. $mysqli->error; echo htmlentities(accepted); ?> <?php else : ?> <p> <span class="error">you not authorized access page.</span> please <a href="index.php">login</a>. </p> <?php endif; ?> </html>
any fixing please?
your js submit values contained in last <form>
way have set up.
the biggest problem here have multiple <form>
elements on page nothing ties button particular form.
i'd suggest use jquery send ajax request each accept or reject instead.
the following articles might help.
Comments
Post a Comment