populate triple drop down in ajax and php in a form - php

I have managed to populate my three drop down lists in php and ajax. Here is the one part of my code that displays the three dropdown lists:
<?php
echo "<font id=\"categoria\"><select>\n";
echo "<option value='0'>Select the Firm</option> \n" ;
echo "</select></font>\n";
?>
<?php
echo "<font id=\"subcategoria\"><select>\n";
echo "<option value='0'>Select the Claims Hub</option> \n" ;
echo "</select></font>\n";
?>
<?php
echo "<font id=\"subcategoria2\"><select>\n";
echo "<option value='0'>Select the Area</option> \n" ;
echo "</select></font>\n";
?>
My question is: I also have a form on this pages and i want to make the three dropdown lists part of my form in order to post the values into another mysql table. Any suggestions how i can do this? Here is my form part:
<form method="post" align= "right">
<table >
<tr><td> </td>
<tr>
<td>Select the Matter Type: </td>
<td><?php echo $dropdown; ?></td>
</tr>
<tr><td> </td>
<tr>
<td style="text-align: left; ">Active </td>
<td align="left" >
<input type="checkbox" name="active" value="1" />
</td>
</tr>
<tr><td> </td>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Add" align= "right" /></td>
</tr>
</table>

Why not just insert them into the html?
<form method="post" align= "right">
<table >
<tr><td> </td>
<tr>
<td>Select the Matter Type: </td>
<td><?php echo $dropdown; ?></td>
</tr>
<tr>
<td>
<?php echo "<font id=\"categoria\"><select><option value='0'>Select the Firm</option></select></font>";?>
</td>
</tr>
<tr><td> </td>
<tr>
<td style="text-align: left; ">Active </td>
<td align="left" >
<input type="checkbox" name="active" value="1" />
</td>
</tr>
<tr><td> </td>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Add" align= "right" /></td>
</tr>

Related

Display dynamic table of checkbox in 3 columns in php

I have a database table of subjects. I have a web page that displays the list of subjects in 3 columns so that a user can select subjects using a checkbox. The challenge I have is it takes a long time for the list to display. The code is below:
<?php
$subjects = mysql_query("select id, name from subjects WHERE exam_type_id='0' OR exam_type_id='$exam_type_id' ORDER BY name");
$noOfSubjects = mysql_num_rows($subjects);
?>
<form name="form1" method="post" action="" class="FormCss" onsubmit=" return window.confirm('You are about to submit selected subjects. If you are not sure, cancel');">
<table>
<tr class="FormLabel2">
<td align="left" colspan="3" valign="top"></td>
</tr>
<?php
$i = 1;
while ($subject = mysql_fetch_array($subjects)){
// if it is a value that is supposed to be in the 1st cell of a row, print tr
if ($i==1 || $i==4 || $i==7 || $i== 10){
?>
<tr>
<?php
}
// print a td if value is not suppose to be the last on a row
if ($i%3 !=0){
?>
<td><input type="checkbox" name="subject[]"
value="<?php echo $subject['id']?>" <?php if (isCompulsoryMockSubject($subject['id'])){?> onclick="return false;" onkeydown="return false;" <?php }else{}?> <?php if (isCompulsoryMockSubject($subject['id'])){?> CHECKED="checked" <?php }else{}?> <?php if (hasSelectedSubject($_SESSION['candidate_id'], $exam_type_id, $subject['id'])){?> checked="checked" <?php }?>><?php echo $subject['name'];?>
</td>
<?php
}else{
// end the row
?>
<td><input type="checkbox" name="subject[]"
value="<?php echo $subject['id']?>" <?php if (isCompulsoryMockSubject($subject['id'])){?> onclick="return false;" onkeydown="return false;" <?php }?> <?php if (isCompulsoryMockSubject($subject['id'])){?> CHECKED="checked" <?php }else{}?> <?php if (hasSelectedSubject($_SESSION['candidate_id'], $exam_type_id, $subject['id'])){?> checked="checked" <?php }?>><?php echo $subject['name'];?>
</td>
</tr>
<?php
}
$i++;
}
?>
<tr>
<td width="34%" align="left" valign="top" class="FormLabel2"> </td>
<td width="33%" align="left" valign="top"><span
class="FormLabel2"> <input name="Submit" type="submit"
class="loginInputSubmit" value="Save"> </span></td>
<td width="33%" align="left" valign="top"> </td>
</tr>
<tr>
<td align="left" valign="top" class="FormLabel2"> </td>
<td colspan="2" align="right" valign="top" class="FormLabel2"> </td>
</tr>
</table>
</form>

Multiple checkbox to a sentence before insert to mysql

I' edit this question with my full coding
Let me post my full code here.
Page1.php
<div id="container">
<div class="box">
<form name="form" method="post" action="userbooking2.php">
<table width="" style="border: 0px solid black" align="center">
<tr>
<td><h2>Book a Room Step 1 - Booking Information</h2></td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="150px" class="titlestyle">Booked by</td>
<td width="400px"><span style="text-transform: uppercase;"><?php echo $_SESSION['SESS_FNAME']; ?></span></td>
</tr>
<tr>
<td class="titlestyle">Title</td>
<td><span class="hint--right" data-hint="Hint : Organization meeting"><input type="text" name="booking_title" id="booking_title" maxlength="50" size="50" /></span></td>
</tr>
<tr>
<td class="titlestyle">Date</td>
<td>From <input type="text" name="booking_start_date" id="booking_start_date"/> to <input type="text" name="booking_end_date" id="booking_end_date"/></td>
</tr>
<tr>
<td class="titlestyle">Time</td>
<td>From <input name="booking_start_time" id="booking_start_time" value="8:00 AM" /> to <input name="booking_end_time" id="booking_end_time" value="8:30 AM"/></td>
</tr>
<tr>
<td class="titlestyle">Room</td>
<td><select name="room_type" id="room_type">
<option value="none">--Select--</option>
<option value="Meeting Room">Meeting Room</option>
<option value="Lecture Room">Lecture Room</option>
<option value="Computer Lab">Computer Lab</option>
</select>
</td>
</tr>
<tr>
<td class="titlestyle">Participant</td>
<td><span class="hint--right" data-hint="Hint : Insert number of participants"><input type="text" name="room_participant" id="room_participant" maxlength="50" size="3" /></span> Persons</td>
</tr>
<tr>
<td class="titlestyle">Equipment</td>
<td><table>
<tr>
<td><input type="checkbox" name="room_facility[]" value="Audio System" />Audio System</td>
<td><input type="checkbox" name="room_facility[]" value="Projector" />Projector</td>
<td><input type="checkbox" name="room_facility[]" value="Video Conferencing" />Video Conferencing</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="titlestyle">Food & Baverages</td>
<td><table>
<tr>
<td><input type="checkbox" name="room_food[]" value="Breakfast" />Breakfast</td>
<td><input type="checkbox" name="room_food[]" value="Tea Break" />Tea Break</td>
<td><input type="checkbox" name="room_food[]" value="Lunch" />Lunch</td>
</tr>
<tr>
<td><input type="checkbox" name="room_food[]" value="High Tea" />High Tea</td>
<td><input type="checkbox" name="room_food[]" value="Dinner" />Dinner</td>
<td><input type="checkbox" name="room_food[]" value="No" />No, thanks</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="titlestyle">Additional Info</td>
<td><span class="hint--right" data-hint="Hint : ."><textarea name="booking_desc" id="booking_desc" style="max-width:400px;" rows="4" cols="50"></textarea></span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="Submit" value="Next" /></td>
</tr>
</table>
</form>
</div>
Page2.php
<?php
//now, let's register our session variables
session_register('fname');
session_register('booking_title');
session_register('booking_start_date');
session_register('booking_end_date');
session_register('booking_start_time');
session_register('booking_end_time');
session_register('room_participant');
session_register('room_type');
session_register('booking_facility');
session_register('booking_food');
session_register('booking_desc');
//finally, let's store our posted values in the session variables
$_SESSION['fname'] = $_SESSION['SESS_FNAME'];
$_SESSION['booking_title'] = $_POST['booking_title'];
$_SESSION['booking_start_date'] = $_POST['booking_start_date'];
$_SESSION['booking_end_date'] = $_POST['booking_end_date'];
$_SESSION['booking_start_time'] = $_POST['booking_start_time'];
$_SESSION['booking_end_time'] = $_POST['booking_end_time'];
$_SESSION['room_participant'] = $_POST['room_participant'];
$_SESSION['room_type'] = $_POST['room_type'];
$_SESSION['room_facility'] = /* WHAT TO SEND HERE? */
$_SESSION['room_food'] = $_POST['room_food'];
$_SESSION['booking_desc'] = $_POST['booking_desc'];?>
// Other form process here
Page3.php
<div id="container">
<div class="box">
<form name="form" method="post" action="">
<table width="" style="border: 0px solid black" align="center">
<tr>
<td><h2>Book a Room Step 3 - Final</h2></td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="150px" class="titlestyle">Booked by</td>
<td width="400px" ><span style="text-transform: uppercase;"><?php echo $_SESSION['SESS_FNAME']; ?></span></td>
</tr>
<tr>
<td class="titlestyle">Title</td>
<td><?php echo $_SESSION['booking_title']; ?></td>
</tr>
<tr>
<td class="titlestyle">Date</td>
<td>From <?php echo $_SESSION['booking_start_date']; ?> to <?php echo $_SESSION['booking_end_date']; ?></td>
</tr>
<tr>
<td class="titlestyle">Time</td>
<td>From <?php echo $_SESSION['booking_start_time']; ?> to <?php echo $_SESSION['booking_end_time']; ?></td>
</tr>
<tr>
<td class="titlestyle">Room</td>
<td><?php echo $_SESSION['room_name']; ?></td>
</tr>
<tr>
<td class="titlestyle">Participant</td>
<td><?php echo $_SESSION['room_participant']; ?> Persons</td>
</tr>
<tr>
<td class="titlestyle">Equipment</td>
<td><?php echo $_SESSION['room_facility']; ?></td>
</tr>
<tr>
<td class="titlestyle">Food & Baverages</td>
<td><?php echo $_SESSION['room_food']; ?></td>
</tr>
<tr>
<td class="titlestyle">Additional Info</td>
<td><?php echo $_SESSION['booking_desc']; ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
In page3.php, i want to view this kind of string "I book Value1, Value2" before store it into the database
Use:
$string = implode(', ', isset($_REQUEST['room_facility']) ? $_REQUEST['room_facility'] : array());
echo 'I need ' . $string;
Then just insert into the database as normal

How to add row in table and in mysql using button or link?

I'm creating a simple database of children and their birthday.
FIDDLE HERE
<?php
$chname1x = mysql_real_escape_string($_POST["chname1"]);
$chbdate1x = mysql_real_escape_string($_POST["chbdate1"]);
$chname2x = mysql_real_escape_string($_POST["chname2"]);
$chbdate2x = mysql_real_escape_string($_POST["chbdate2"]);
$chname3x = mysql_real_escape_string($_POST["chname3"]);
$chbdate3x = mysql_real_escape_string($_POST["chbdate3"]);
$chname4x = mysql_real_escape_string($_POST["chname4"]);
$chbdate4x = mysql_real_escape_string($_POST["chbdate4"]);
$chname5x = mysql_real_escape_string($_POST["chname5"]);
$chbdate5x = mysql_real_escape_string($_POST["chbdate5"]);
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$conn=mysql_connect($dbhost,$dbuser,$dbpass) or die ('Could not connect to mysql');
$dbname='onlinepdsdb';
mysql_select_db($dbname);
if ($_POST['submitbutton'])
{
$query="INSERT INTO children (chname1,chbdate1,chname2,chbdate2,chname3,chbdate3,chname4,chbdate4,chname5,chbdate5) VALUES ('$chname1x', '$chbdate1x','$chname2x', '$chbdate2x','$chname3x', '$chbdate3x','$chname4x', '$chbdate4x','$chname5x', '$chbdate5x')";
mysql_query($query) or die (mysql_error());
echo "The user $uid has been succesfully registered.";
echo $query;
echo $uid;
}
<center>
<form method='POST' action='formchildren.php'>
<table border='3' style='width:700px'>
<tr bgcolor='#3399FF'>
<td colspan='2' class='head2' height='20'>NAME OF CHILD (Write full name and list all)</td>
<td colspan='3' class='head2' height='20'>DATE OF BIRTH (mm/dd/yyyy)</td>
</tr>
<tr>
<td class='numbering'>1.</td>
<td style='text-align:center;'>
<input type='text' name='chname1' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate1' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>2.</td>
<td style='text-align:center;'>
<input type='text' name='chname2' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate2' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>3.</td>
<td style='text-align:center;'>
<input type='text' name='chname3' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate3' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>4.</td>
<td style='text-align:center;'>
<input type='text' name='chname4' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate4' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>5.</td>
<td style='text-align:center;'>
<input type='text' name='chname5' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate5' size='45' maxlength='50'>
</td>
</tr>
<tr><input type='SUBMIT' name='submitbutton'></tr>
</table>
</form>
I created here a 5 rows, but if the children is more than 5 there is no more rows. I want to put a link/button that if clicked will add a row in table and in mysql but I don't have any idea how.
You can use jQuery .append()
here are the source jQuery Append
using append:
e.g. by click a button, you can append another textbox and dropdown list
It's in you on how you can do this.. This is just a tip. ;)
example here:
http://jsfiddle.net/lian23/Sz73b/
Your form's submit button fields are backwards. Switch the type & name.
The type should be "submit", and the name "submitbutton"
eg
<input type='submit' name='submitbutton'>
This way, the HTML will be correct and your PHP code will be looking for the right field name:
if ($_POST['submitbutton'])

I want to submit this form into DB php

i want to insert this below given form data to database, but i dont know how to do this, it is about inserting product to multiple warehouse with different quantities, when checkbox against the warehouse name is checked than the quantity textbox appears.
and this is my PHP code
<form name="form1" method="post" action="product_insert.php" enctype="multipart/form-data">
<table>
<tr>
<td width="274" align="right" height="25"><strong>Product Name :</strong></td>
<td><input type="text" name="wproname" value="" /></td>
</tr>
<tr>
<td width="274" align="right" height="25"><strong>Select Warehouse :</strong></td>
<td width="500"><table style="border:none">
<tr >
<td> Select </td>
<td> Name </td>
<td> Quantity </td>
</tr>
<?php
$sql="select * from tbl_warehouse where w_flag='1'";
$result=ExecuteGetRows($sql);
$num_rows=count($result); ?>
<?php for($i=0;$i<$num_rows;$i++){ ?>
<tr>
<td><input type="checkbox" name="chk<?php echo $result[$i]['w_id'];?>" value="<?php echo $result[$i]['w_id'];?>" id="chk<?php echo $result[$i]['w_id'];?>" onChange="display<?php echo $result[$i]['w_id'];?>();" />
</td>
<td><?php echo $result[$i]['w_name'];?></td>
<td><input type="text" name="qty<?php echo $result[$i]['w_id'];?>" id="qty<?php echo $result[$i]['w_id'];?>" style="display:none" />
</td>
</tr>
<script>
function display<?php echo $result[$i]['w_id'];?>()
{
if(document.getElementById("chk<?php echo $result[$i]['w_id'];?>").checked)
{
document.getElementById("qty<?php echo $result[$i]['w_id'];?>").style.display="block";
}
if(!document.getElementById("chk<?php echo $result[$i]['w_id'];?>").checked)
{
document.getElementById("qty<?php echo $result[$i]['w_id'];?>").style.display="none";
}
}
</script>
<?php } ?>
</table></td>
</tr>
<tr>
<td align="right"></td>
<td width="296"><input type="submit" name="Submit" value="Add New" align="middle" class="button login_btn"/></td>
</tr>
</table>
</form>
And I am using this php code for inserting data to the database
$sqls=mysql_query("select * from tbl_warehouse");
while($result=mysql_fetch_array($sqls)) {
$w = $result['w_id'];
echo $_POST['chk'.$w];
foreach($_POST['chk'.$w] as $key=>$val) {
echo $_POST['chk'.$w];
$sql = "INSERT INTO tbl_product(p_id,w_id,p_name,p_qty) values ('','".$wid."','".$wproname."','".$qty."')";
mysql_query($sql);
}
}
You don't need the leading comma in your values list in your insert statement. So change this:
"INSERT INTO tbl_product(p_id,w_id,p_name,p_qty) values ('','".$wid."','".$wproname."','".$qty."')";
To this:
"INSERT INTO tbl_product(p_id,w_id,p_name,p_qty) values ('".$wid."','".$wproname."','".$qty."')";

php - drop down from database

Im a newbie ih php.Im trying to show drop down list values from database using this but the data not shown up.There is no error as well. Need some experts advice.
Code
<?php
include('connectdb.php');
$sql="SELECT id,name FROM companydetailstbl";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
//echo $id;
$thing=$row["name"];
$options.="<OPTION VALUE=\"$id\">".$thing;
}
?>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Company Name </td>
<td width="3%">:</td>
<td width="75%"><SELECT NAME="thing">
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT></td>
</tr>
<tr>
<td>Installation Date </td>
<td>:</td>
<td><input type="text" name="ins_dt" />
(ddmmyyyy)</td>
</tr>
<tr>
<td>Expiry Date </td>
<td>:</td>
<td><input type="text" name="ex_dt" />
(ddmmyyyy)</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Update" />
<input type="submit" name="Submit2" value="Reset" /></td>
</tr>
</table>
Please help. Thanks
I don't know what DTD you are currently using, but according to the HTML 4.0 Specification, you need to close your option tag.
$options .= '<option value="' . $id . '">' . $thing . '</option>';
Also there,
<select name="thing">
<option value="0">Choose</option>
<?php echo $options; ?>
</select>
please try to close the tag
$options.="<OPTION VALUE=\"$id\">".$thing."</OPTION>";
also edit
<SELECT NAME="thing">
<OPTION VALUE=0>Choose</OPTION>
<?=$options?>
</SELECT>
<?php
include('connectdb.php');
$sql="SELECT id,name FROM companydetailstbl";
$result=mysql_query($sql);
?>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Company Name </td>
<td width="3%">:</td>
<td width="75%">
<select name="thing">
<?php
while($row = mysql_fetch_object($result)){
?>
<option value="<?=$row["id"]; ?>"><?=$row["name"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Installation Date </td>
<td>:</td>
<td><input type="text" name="ins_dt" />(ddmmyyyy)</td>
</tr>
<tr>
<td>Expiry Date </td>
<td>:</td>
<td><input type="text" name="ex_dt" />(ddmmyyyy)</td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="Submit" value="Update" />
<input type="submit" name="Submit2" value="Reset" />
</td>
</tr>
</table>
Hope it helps

Categories