I have a program which appends an input(type="hidden") using jquery, to an html so that when I click the submit button, it passes the value to a php file and I can process it. However, it seems that the hidden type is not really being appended to the html nor it is being passed to the php file. I already used method="get" to see the values in the address bar and print_r to see the values being catched but there's nothing. To check if my form is actually passing a value, I added a
<input type="hidden" name="absent[]" value="testing" />
in the HTML and the value got passed but the ones in the jquery aren't.
Here are my files:
jquery:
$(function(){
$("td").click(function(){
if($(this).hasClass("on"))
{
alert("Already marked absent");
}
else
{
$(this).addClass("on");
var currentCellText = $(this).text();
var temp = $(this).attr('id');
$("#collect").append("<input type='hidden' name='absent[]' value = '" + temp + "'/>" + currentCellText);
alert(temp);
}
});
$("#clicky").click(function(){
$("td").removeClass("on");
$("#collect").text('');
$("#collect").append("Absentees: <br>")
alert(temp);
});
});
Here is the html part:
<?php
session_start();
include 'connectdb.php';
$classID = $_SESSION['csID'];
$classQry = "SELECT e.csID, c.subjCode, c.section, b.subj_name, e.studentID, CONCAT(s.lname, ', ' , s.fname)name
FROM ENROLLMENT e, CLASS_SCHEDULE c, STUDENT s, SUBJECT b
WHERE e.csID = c.csID
AND c.csID = '" . $classID . "'
AND c.subjCode = b.subjCode
AND e.studentID = s.studentID
ORDER BY e.sort;";
$doClassQry = mysql_query($classQry);
echo "<table id='tableone'>";
while($x = mysql_fetch_array($doClassQry))
{
$subject = $x['subj_name'];
$subjCode = $x['subjCode'];
$section = $x['section'];
$studentArr[] = $x['name'];
$studentID[] = $x['studentID'];
}
echo "<thead>";
echo "<tr><th colspan = 7>" . "This is your class: " . $subjCode . " " . $section . " : " . $subject . "</th></tr>";
echo "</thead>";
echo "<tbody>";
echo "<tr>";
for($i = 0; $i < mysql_num_rows($doClassQry); $i++)
{
if($i % 7 == 0)
{
echo "</tr><tr><td id = '". $studentID[$i] . " '>" . $studentArr[$i] . "</td>";
}
else
{
echo "<td id = '". $studentID[$i] . " '>" . $studentArr[$i] . "</td>";
}
}
echo "</tr>";
echo "</tbody>";
echo "</table>";
?>
Here's the html part with the form:
<form name="save" action="saveTest.php" method="post">
<div id="submitt">
<input type="hidden" name="absent[]" value="testing"/>
<input type="submit" value="submit"/>
</div>
</form>
And here's the php part which processes the form (saveTest.php):
<?php
$absent = $_POST['absent'];
//echo "absnt" . $absent[] . "<br>";
echo count($absent) . "<br>";
//print_r($_POST) . "<br>";
?>
Is the element with id collect inside the form? It needs to be.
$("<input type='hidden' name='absent[]' />").val(temp)
.appendTo('form[name="save"]');
$('#collect').append(currentCellText);
This works perfectly.
$("body").delegate("#editorjs_menu_list ul li a", "click", function(e){
e.preventDefault();
$(this).toggleClass("active");
});
Related
Here is my code and i need to insert array values in $testar in to the table patients_testings. But it doesn't work with this code, where is the error? if i can do this using one global variable. it will be more helpful. thank you.
<form role="form" method="post" action="" name="testing" onsubmit="return validate_form()">
<?php
$sqltestin = "SELECT * FROM testings";
$querytestin = mysqli_query($dbhandle, $sqltestin);
while ($rowtestin = mysqli_fetch_assoc($querytestin)) {
echo '<input type="checkbox" name="testingar[]" value="' . $rowtestin['TestId'] . '">' . $rowtestin['TestName'] . '<br>';
}
?>
<div class="modal-footer">
<input type="submit" name="submittestin" id="submittestin" class="btn btn-success" value="Add Tests">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div></div>
<?php
$checkBox = '';
$testar = '';
if (isset($_POST['submittestin'])) {
global $checkBox;
global $testar;
$checkBox = $_POST['testingar'];
foreach ($checkBox as $testar1) {
$testar .= $testar1 . ",";
}
$tot = 0.00;
for ($i = 0; $i < sizeof($checkBox); $i++) {
$queryt2 = "SELECT * FROM testings WHERE TestId = $checkBox[$i] ";
$resultt2 = mysqli_query($dbhandle, $queryt2) or die (mysql_error());
while ($rowt2 = mysqli_fetch_assoc($resultt2)) {
echo "<tr><td>" . $rowt2['TestName'] . "</td>";
echo "<td width='100'>" . $rowt2['specimen'] . "</td>";
echo "<td>" . $rowt2['HopePrice'] . "</td></tr>";
//echo '<br/>';
$tot = $tot + $rowt2['HopePrice'];
}
}
echo "<tr><td><b>Total</b></td><td <b>:</b></td><td><b>" . number_format($tot, 2) . "</b></td></tr>";
echo "<tr><td><form role='form' method='post' action=''><input type='submit' name='printinv' id='printinv' class='btn btn-success' value='Print'></form></td></tr>";
//echo $testar;
if (isset($_POST['printinv'])) {
$sqltnum = "INSERT INTO patients_testings VALUES ('$ref_no','$testar')";
if (mysqli_query($dbhandle, $sqltnum) or die (mysql_error())) {
echo "Entered Successfully";
//}
}
}
}
?>
Why your code does not work:
I think the concept that you are missing is that when the page is requested, and on every subsequent form submission, the PHP code is executed then exits which throws out the values of the variables stored in memory. Making the variables global does not make them persist between requests.
Specifics to your code:
The first time the form is submitted isset($_POST['submittestin']) is true and it successfully populates the $testar variable with data. However, on the second post isset($_POST['submittestin']) is false and so you never hit the if (isset($_POST['printinv'])) section. Now, even if you move the if (isset($_POST['printinv'])) outside the first if ... submittestin you still have a problem because the $testar will no longer be populated with data.
Additionally, you use variables which are never initialized anywhere that I can see. $ref_no is an example.
I would also suggest echoing out your DB queries to see if they are properly formatted before you run them. I think that some of them may be missing 's in places.
How to make data persist between requests?
The best way is to start a session. By starting a session you can save variables in the $_SESSION array and then access them durring a different request.
Note: You cannot serialize resorces so you will need to reconnect to the database on each request. I.e., this won't work: $_SESSION['dbhandle'] = $dbhande;
Another way to set <input type=hidden ... elements in your form so that on the second post you can access them again through the $_POST variable.
Attempt to make your code use sessions:
<?php
session_start();
?>
<form role="form" method="post" action="" name="testing" onsubmit="return validate_form()">
<?php
$sqltestin = "SELECT * FROM testings";
$querytestin = mysqli_query($dbhandle, $sqltestin);
while ($rowtestin = mysqli_fetch_assoc($querytestin)) {
echo '<input type="checkbox" name="testingar[]" value="' . $rowtestin['TestId'] . '">' . $rowtestin['TestName'] . '<br>';
}
?>
<div class="modal-footer">
<input type="submit" name="submittestin" id="submittestin" class="btn btn-success" value="Add Tests">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div></div>
<?php
$checkBox = '';
$testar = '';
if (isset($_POST['submittestin'])) {
global $checkBox;
global $testar;
$checkBox = $_POST['testingar'];
foreach ($checkBox as $testar1) {
$testar .= $testar1 . ",";
}
$_SESSION['testar'] = $testar;
$_SESSION['ref_no'] = "This gets used below but I don't see it initialized anywhere?";
$tot = 0.00;
for ($i = 0; $i < sizeof($checkBox); $i++) {
$queryt2 = "SELECT * FROM testings WHERE TestId = '".$checkBox[$i]."'"; // syntax issue here
$resultt2 = mysqli_query($dbhandle, $queryt2) or die (mysql_error());
while ($rowt2 = mysqli_fetch_assoc($resultt2)) {
echo "<tr><td>" . $rowt2['TestName'] . "</td>";
echo "<td width='100'>" . $rowt2['specimen'] . "</td>";
echo "<td>" . $rowt2['HopePrice'] . "</td></tr>";
//echo '<br/>';
$tot = $tot + $rowt2['HopePrice'];
}
}
echo "<tr><td><b>Total</b></td><td <b>:</b></td><td><b>" . number_format($tot, 2) . "</b></td></tr>";
echo "<tr><td><form role='form' method='post' action=''>";
echo "<input type='submit' name='printinv' id='printinv' class='btn btn-success' value='Print'>";
echo "</form></td></tr>";
}
//echo $testar;
if (isset($_POST['printinv'])) {
if(isset($_SESSION['testar']) {
$testar = $_SESSION['testar'];
$ref_no = $_SESSION['refno'];
$sqltnum = "INSERT INTO patients_testings VALUES ('$ref_no', '$testar')"; // Where is $ref_no set?
if (mysqli_query($dbhandle, $sqltnum) or die (mysql_error())) {
echo "Entered Successfully";
}
}
}
?>
I am trying to add CSS to my form but not sure how to do this. The form is created in php and MySQL, in browser it looks like: http://gyazo.com/5d099ead9bd6ea83859a5114b2438748
I need to allign the text and drop downs so they are in the equal throughout and add some spacing. Anyone help with CSS for this?
html currently:
<div class="wrap">
<img src="/images/logo.png" alt="Highdown logo" />
<h1>Entry form</h1>
</div>
css currently:
.wrap {
position: relative;
}
The form is produced with this:
if ($event_result = $con->query("SELECT Event.Name FROM event")) {
echo "<form method =\"POST\" action=\"save.php\"> ";
while ($row = $event_result->fetch_assoc()) {
echo $row['Name']. ' ';
if ($student_result = $con->query("SELECT Student.Form, Teacher.Form, Student.Forename, Student.Surname, Student_ID " .
"FROM Student, Teacher " .
"WHERE Student.Form = Teacher.Form AND Teacher.Username = '" . $_SESSION['Username'] . "'")) {
if ($student_result->num_rows) {
echo "<select name ='". $row['Name']."'>";
while ($row1 = $student_result->fetch_assoc()) {
echo '<option value="" style="display:none;"></option>';
echo "<option value ='" . $row1['Student_ID'] . "'>" . $row1['Forename'] . ' ' . $row1['Surname'] . "</option>";
}
echo "</select> <br />";
}
}
}
echo '<input type="submit" value ="Submit">';
echo '<input type="reset" value ="Reset">';
echo '<input type="button" value = "Add student" onclick="location.href=\'http://localhost/sportsday/addstudent.php\'">';
echo '<input type="button" value = "Delete student">';
echo "</form>";
}
Use
<form>
<table>
<tr> //1st Table row
<td></td> //Table column data
<td></td> //table column data
</tr> //1st row ends
<tr> // 2nd Table row
<td></td> //Table column data
<td></td> //table column data
</tr> //2nd row ends
</table>
</form>
This will give you a better layout of the form.
This should work i did not try as i dont have the database
//Query to display all events
if ($event_result = $con->query("SELECT Event.Name FROM event")) {
echo "<form method =\"POST\" action=\"save.php\"> ";
echo '<table>';
echo '<tr>';
echo '<td>';
while ($row = $event_result->fetch_assoc()) {
echo $row['Name']. ' ';
echo '</td>';
if ($student_result = $con->query("SELECT Student.Form, Teacher.Form, Student.Forename, Student.Surname, Student_ID " .
"FROM Student, Teacher " .
"WHERE Student.Form = Teacher.Form AND Teacher.Username = '" . $_SESSION['Username'] . "'")) {
if ($student_result->num_rows) {
echo '<td>';
echo "<select name ='". $row['Name']."'>";
while ($row1 = $student_result->fetch_assoc()) {
echo "<option value ='" . $row1['Student_ID'] . "'>" . $row1['Forename'] . ' ' . $row1['Surname'] . "</option>";
}
echo "</select> <br />";
echo '</td>';
echo '</tr>';
}
}
}
echo '</table>';
echo '<input type="submit" value ="Submit">';
echo '<input type="reset" value ="Reset">';
echo '<input type="button" value = "Add student" onclick="location.href=\'http://localhost/sportsday/addstudent.php\'">';
echo '<input type="button" value = "Delete student">';
echo "</form>";
}
?>
you can directly write in css
form {
⋮ declare css
}
or give name to form
form[name="value"]{
⋮ declare css
}
or add any class or id on form
#formid{
⋮ declare css
}
.formclass{
⋮ declare css
}
First , check your database...
May be there is Another Issue not related to Tabular Output.
So , First remove Table Tag..and check whether its working ?
Then try in HTML TABLE TAG
Otherwise give me sample database .sql File and complete PHP code in google drive or on shared drive.
So that I can check and identify where is problem ?
I have this code but when I press the submit button No data is being transferred via Get, with the exemption on the submit.
<table cellspacing="0px">
<tr>
<td>Name</td><td>Today - <?php echo $date;?></td>
</tr>
<form method="get" action="update_reg.php">
<?php
$result = mysqli_query($con,"SELECT * FROM TABLE WHERE GROUP = 'Penguins' ORDER BY Rank, Name ");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>";
if($row['Rank'] == "a"){
$rank = "TOP ";
}
if($row['Rank'] == "b"){
$rank = "MIDDLE ";
}
if($row['Rank'] == "c"){
$rank = "SECOND ";
}
if($row['Rank'] == "d"){
$rank = "BOTTOM ";
}
if($row['Rank'] == "e"){
$rank = "";
}
echo $rank . $row['Name'] . "</td>";
$num = $num + 1;
echo "<td><input type=\"text\" class=\"today\" id=\"" . $row['id'] . "\" data-number=\"" . $num . "\" size=\"1\" maxlength=\"1\"></td></tr>";
}
?>
</table>
<input type="submit" value="submit">
</form>
For some reason this isn't working, anyone got any ideas why? Thanks in advance.
You need to add a value="" attribute and name="" attribute to your <input>s.
For example:
echo "<td><input type=\"text\" class=\"today\" id=\"" . $row['id'] . "\" name=\"" . $row['id'] . "\" data-number=\"" . $num . "\" value=\"" . $num . "\" size=\"1\" maxlength=\"1\"></td></tr>";
I'm not sure what you're trying to submit exactly, but place that in the value for the value attribute and make sure to give each one a name attribute and value. In my example, I used $num for the value and $row['id'] for the name.
None of your <input> tags have name attributes. No name, no form submission.
GROUP is a reserved keyword.
So you need to backtick it as
`GROUP`
SELECT * FROM TABLE WHERE `GROUP` = 'Penguins' ORDER BY Rank, Name
UPDATE FROM LAST COMMENT
Input need a name which is not there and if you give same name for all of them they will not work. So give a name="something[]" and on submit get the data as array
im creating an invoice function. It involves 3 pages.
The first page which is a form that takes in the variable of customer name, description, amount, quantity and discount.
The second page parses all these variable, make a new variable called total that will calculate amount X quantity minus away the discount and then insert into database then redirect to the third page.
The Third Page
Is supposed to sum the total column for a final total variable. How do i use the sum function to calculate the total in order to get the final total? And also how do i store all the variables printed out so that i can store them into database?
E.g. i want to print out all the descriptions, customer name, amount, quantity and total entered in page one and then add the final total which was calculated in page 3 .
Page one(submit form)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var count = 0;
function addTextArea() {
count = count + 1;
var div = document.getElementById('name');
div.innerHTML += "<div> <input type='text' name='name[]' value='' " + "id=name" + count + "> </div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('quantity');
div.innerHTML += "<div><input type='text' name='quantity[]' value ='' " + "id=quantity" + count + "></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('amount');
div.innerHTML += "<div><input type='text' name='amount[]' value ='' " + "id=amount" + count + "></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('discount');
div.innerHTML += "<div><input type='text' name='discount[]' value ='' " + "id=discount" + count + "></div>";
div.innerHTML += "\n<br />";
}
function removeTextArea() {
document.getElementById("name" + count).remove();
document.getElementById("quantity" + count).remove();
document.getElementById("amount" + count).remove();
document.getElementById("discount" + count).remove();
count = count - 1;
}
</script>
</head>
<body>
<form action="invoicesubmit.php" method="POST">
<?php
echo "<table border='2'>\n";
echo "<tr>\n";
echo "<th>Description</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "</tr>"; echo "<tr>";
echo "<td>"?>
<input type='text' size="50" name='name[]' value='Examination and Consultation' readonly/>
<?php "</td>"; echo "<td>"?>
<input type='text' size="50" name='quantity[]' value='' />
<?php "</td>";
echo "<td>"?>
<input type='text' size="50" name='amount[]' value='' />
<?php "</td>";
echo "<td>"?>
<input type='text' size="50" name='discount[]' value='' />
<?php "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"?>
<div id="name"></div>
<?php "</td>"; echo "<td>"?>
<div id="quantity"></div>
<?php "</td>"; echo "<td>"?>
<div id="amount"></div>
<?php "</td>"; echo "<td>"?>
<div id="discount"></div>
<?php "</td>";
echo "</tr>"; ?> <br />
<input type="button" value="Add Description" onClick="addTextArea();">
Customer Name: <input type="text" value="" name="cust_name" />
<input type="button" value="Remove Description" onClick="removeTextArea();">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Page Two (Store into database)
<?php require_once ("includes/session.php");?>
<?php require_once ("includes/db_connection.php");?>
<?php require_once ("includes/functions.php");?>
<?php require_once ("includes/validation_function.php");?>
<?php
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Description</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Total_amt</th>\n";
echo "</tr>";
<?php
if (isset($_POST['submit']))
{ // Process the form
$name_array = $_POST['name'];
$quantity_array = $_POST['quantity'];
$amount_array = $_POST['amount'];
$discount_array = $_POST['discount'];
for ($i = 0; $i < count($name_array); $i++)
{
$name = $name_array[$i];
$quantity = $quantity_array[$i];
$amount = $amount_array[$i];
$discount = $discount_array[$i];
$total_amt = ($amount - ($amount * ($discount / 100))) * $quantity;
$cust_name = mysqlprep($_POST["cust_name"]);
global $connection;
$query = "INSERT INTO invoicesub (";
$query.= " cust_name, description, quantity, amount, discount, total";
$query.= ") VALUES (";
$query.= " '{$cust_name}', '{$name}', {$quantity}, {$amount}, {$discount}, {$total}";
$query.= ")";
$result = mysqli_query($connection, $query);
echo "<tr>";
echo "<td>" . $name . "</td>";
echo "<td>" . $quantity . "</td>";
echo "<td>" . "$" . $amount . "</td>";
echo "<td>" . $discount . "%" . "</td>";
echo "<td>" . "$" . $total_amt . "</td>";
echo "</tr>";
if ($result)
{
redirect_to("invoicesubmitfinal.php");
}
}
?>
page three (Print and store into 2nd database)
<?php
$query = "SELECT * ";
$query.= "FROM invoicesub";
$result = mysqli_query("SELECT sum(amount) FROM invoicesub") or die(mysqli_error());
while ($rows = mysql_fetch_array($result))
{
$result1 = mysqli_query("SELECT sum(quantity) FROM invoicesub") or die(mysqli_error());
while ($rows1 = mysqli_fetch_array($result1))
{
$result2 = mysqli_query("SELECT sum(total) FROM invoicesub") or die(mysqli_error());
while ($rows2 = mysqli_fetch_array($result2))
{
echo $rows['amount'];
echo $rows1['quantity'];
echo $rows2['total'];
$finaltotal = $rows2['total'];
}
}
}
?>
Since, your requirement is not really understandable, i tried clearing some errors & changed the SQL. if you, refrain your questions, along with the included function & connection files, we can only take a look. The modified codes are shown below.
invoicesubmit.php
<?php require_once ("includes/session.php");?>
<?php require_once ("includes/db_connection.php");?>
<?php require_once ("includes/functions.php");?>
<?php require_once ("includes/validation_function.php");?>
<?php
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Description</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Total_amt</th>\n";
echo "</tr>";
if (isset($_POST['submit'])){ // Process the form
$name_array = $_POST['name'];
$quantity_array = $_POST['quantity'];
print_r($quantity_array);
$amount_array = $_POST['amount'];
$discount_array = $_POST['discount'];
for ($i = 1; $i < count($name_array); $i++){
$name = $name_array[$i];
$quantity = $quantity_array[$i];
$amount = $amount_array[$i];
$discount = $discount_array[$i];
$total_amt = ($amount - ($amount * ($discount / 100))) * $quantity;
$cust_name = mysqlprep( $_POST["cust_name"]);
global $connection;
$query = "INSERT INTO invoicesub (";
$query.= " cust_name, description, quantity, amount, discount, total";
$query.= ") VALUES (";
$query.= " '{$cust_name}', '{$name}', {$quantity}, {$amount}, {$discount}, {$total_amt}";
$query.= ")";
$result = mysqli_query($connection, $query);
echo "<tr>";
echo "<td>" . $name . "</td>";
echo "<td>" . $quantity . "</td>";
echo "<td>" . "$" . $amount . "</td>";
echo "<td>" . $discount . "%" . "</td>";
echo "<td>" . "$" . $total_amt . "</td>";
echo "</tr>";
}
if ($result){
redirect_to("invoicesubmitfinal.php?cname=$cust_name");
}
}
?>
invoicesubmitfinal.php
<?php
require_once ("includes/db_connection.php");
global $connection;
$name=$_REQUEST['cname'];
$sql1="SELECT sum(amount) as amount, sum(quantity) as quantity, sum(total) as total FROM invoicesub where cust_name=$name";
$result = mysqli_query($connection, $sql1) or die(mysqli_error());
while ($rows = mysql_fetch_array($result)){
echo $rows['amount'];
echo $rows['quantity'];
echo $rows['total'];
}
?>
Assume that I have a directory page that is generated by PHP. Each row data is from the database.
echo "<form action=\"reservation.php\" method=\"post\">";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
if ( stripslashes($row['gymid']) == !0) {
echo "<tr>". PHP_EOL;
echo "<td>".stripslashes($i+1)."</td>". PHP_EOL;
echo "<td align=\"center\">".stripslashes($row['gymname'])."</td>". PHP_EOL;
echo "<td>".stripslashes($row['address'])."</td>". PHP_EOL;
echo "<td align=\"center\">".stripslashes($row['location'])."</td>". PHP_EOL;
echo "<td align=\"center\">".stripslashes($row['operatinghours'])."</td>". PHP_EOL;
echo "<td align=\"center\"><input type= \"submit\" id =\"gym".stripslashes($row['gymid'])."\" value=\"BOOK NOW\" class=\"bookbutton\" onClick=\"reply_click(this.id)\"</td>". PHP_EOL;
//echo "<td align=\"center\"><input type=\"submit\" name=\"gyminfo\" class=\"bookbutton\" value=\"".stripslashes($row['gymid'])."\" >BOOK NOW! </td>". PHP_EOL;
echo "</tr>". PHP_EOL;
}
}
echo "</form>";
So i have a "BOOK NOW" button for each row with unique id (gymxxxx). Upon clicking that button, the page will be redirect to reservation.php where there are a few dropdown boxes with gymname, location, timeslot and so on.
The following shows the dropdown box for gymname:
<label>Gym Name: </label>
<form id="gymInfoForm" method = "post" action = "reservation.php">
<select name="gymSelect"onchange="if (this.selectedIndex) formSubmit();">
<?php
$data = $_POST['gymSelect'];
echo "Data = " . $data;
$query = "SELECT * FROM gymname";
$result = $db->query($query);
$resultNum = $result->num_rows;
echo '<option value="NULL" >Please choose a gym</option>';
for($i = 0; $i < $resultNum; $i++)
{
$row = $result->fetch_assoc();
if($data == $row['gymname'])
{
echo '<option value="' . $row['gymname'] . '" selected>' . $row['gymname'] . '</option>'.PHP_EOL;
}
else
{
echo '<option value="' . $row['gymname'] . '" >' . $row['gymname'] . '</option>'.PHP_EOL;
}
}
?>
</select>
</div>
<div style="margin-bottom:10px">
My question is, how can i post the data (gymname and location) linked to the "BOOK NOW" button to the reservation.php such that the option for "gymname" and "location" will be preselected?
Thank you!
U can do <form> tag for each row or use JS witch map your data and send to the server.
It doesn't look like you have any 'names' for your inputs:
put:
name='bookNow'
in the book now button input tag.
Then put
name='gymName'
in your pre-populated gym name input tag.
Then you can get the values with php:
if(isset($_POST['bookNow'])){
$gymName = $_POST['gymName'];
}