saving the dynamically added textboxes in php - php

hi i am working on a form which has an ability to add table rows on button click but the problem is that the my php for loop is saving the first row and not saving the other textboxe values. i am stuck. here is my code
<form class="form-horizontal" name="invoice" method="POST">
<div id="div-2" class="accordion-body collapse in body">
<div style="max-height:300px;overflow: auto; border: 0px solid;">
<div style="float:left; margin-right:-8220000px;">
<table id="data" border="1px" width="90%">
<tr>
<td width="60px" align="center"> <label class="control-label">Sr No.</label></td>
<td width="250px" align="center"><label class="control-label">Item Name</label></td>
<td width="90px" align="center"><label class="control-label">Qty</label></td>
<td width="50px" align="center"><label class="control-label">Unit</label></td>
<td width="100px" align="center"><label class="control-label">Rate</label></td>
<td width="120px" align="center"><label class="control-label">Amount</label></td>
<td width="200px" align="center"><label class="control-label">Marks& Nos</label></td>
<td width="250px" align="center"><label class="control-label">Description</label></td>
</tr>
<tr>
<td align="left"><input type="text" size="6" maxlength="6" maxlength="6" name="srno_0" class="sno form-control"/></td>
<td align="left">
<select data-placeholder="Item" name="item_0" class="form-control" >
<option value=""></option>
<?php
$mown = mysql_query("SELECT code, `name` FROM `item`") or die(mysql_error());
while ($trow = mysql_fetch_array($mown)) {
echo "<option value=$trow[code]>$trow[name]</option>";
}
?>
</select>
</td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="qty_0" class="qty form-control" style='text-align:right'/></td>
<td align="left">
<input type="text" size="6" maxlength="6" name="unit_0" class="unit form-control"/>
</td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="rate_0" class="rate form-control" style='text-align:right'/></td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="amt_0" id="amount" class="amt form-control" style='text-align:right' readonly/></td>
<td align="center"><input type="text" size="6" name="marks_0" class="trip form-control"/></td>
<td align="center"><textarea name="descrip_0" cols="90" rows='1' class="desc form-control"></textarea></td>
</tr>
</table>
</div>
</div>
<table border='0' width='100%'>
<tr>
<td width="150px">
<input type="button" id="addnew" class="btn btn-success btn-lg" name="addnew" value="+" />
<input type="hidden" id="items" name="items" value="<?php echo ($addflag == 0) ? $ctr : 1; ?>" />
</td><td width="240px"></td><td width="140px"></td><td width="200px" align="right"><label for=""><font color="black" size="3px">SubTotal</font><span></span></label></td>
<td width="200px"><input id="total" type="text" name="total" class="form-control" value="<?php echo ($addflag == 0) ? $get['total'] : "0.00"; ?>" readonly style='text-align:right'></td>
</tr>
here is my jquery code
<script type='text/javascript'>
$(document).ready(function() {
$('#data').on('keyup', '.qty, .rate, .amt', calculateRow);
$('#data').on('blur', '.desc', addrows);
function addrows(){
var ctr = $('#items').val();
$.post('bmt_invsrch.php', {ctr: ctr}, function(data) {
$(data).appendTo('#data');
ctr++;
$('#items').val(ctr);
});
}
$('#addnew').click(function() {
addrows();
});
});
</script>
here is my php
for ($i = 0; $i<$count; $i++){
$msrno = $_POST["srno_$i"];
$mitem = $_POST["item_$i"];
$mqty = $_POST["qty_$i"];
$munit = $_POST["unit_$i"];
$mrate = $_POST["rate_$i"];
$mamt = $_POST["amt_$i"];
$mmarks = $_POST["marks_$i"];
$mdescrip = $_POST["descrip_$i"];
mysql_query("INSERT INTO `saletran`(vouchno, srno, item, qty, unit, rate, amt, marks, descrip)
VALUES('$mvouch', '$msrno', '$mitem', '$mqty', '$munit', '$mrate', '$mamt', '$mmarks', '$mdescrip')") or die(mysql_error());
}

You can group you input fields, something like this
<form method='post'>
<input type='text' name='test[]' />
<input type='text' name='test[]' />
<input type='text' name='test[]' />
<input type='text' name='test[]' />
<input type='submit' value='submit' name='submit'/>
</form>
When you submit this form the result will be something like
Array
(
[test] => Array
(
[0] => 21
[1] => 212
[2] => 121
[3] => 21
)
[submit] => submit
)

Related

Add dynamic inputs and insert data to MySQL using PHP

I have a form which has inputs and there is a link called 'Add New Rows' that adds the same row underneath to insert more data if its needed with a remove Row Option. And when i click save button it should save the form with the data already having and the data which i added with Add New Rows. I tried different ways to achieve it, but nothing is working out. Iam putting the form.php page and save.php page.
Form.php is below:
echo "<form name='cart' method='post' class='single' action='price_add_save.php'>";?>
while ($list5 = mysql_fetch_array($result)) {
$slno1++;
echo '<tbody>';
echo '<tr>';
echo "<td width='4%' class='addinput'><a href='#' class='addNew'>Add New</a><input size='1' type='hidden' name='id[$i]' value='{$list5['item_id']}' readonly/><input size='1' type='text' id='sl[$i]' name='sl[$i]' name='sl[$i]' value='{$list5['slno']}' readonly/><input size='1' type='hidden' id='item_id[$i]' name='item_id[$i]' value='{$list5['item_id']}' readonly/></td>";
echo "<td width='4%'><select id='ifmain[$i]' name='ifmain[$i]'><option value='Yes'>Main Item</option><option value='No'>Sub Item</option></select></td>";
echo "<td width='10%' id='addinput'><input type='text' size='15' id='item_name$i' name='item_name[$i]' placeholder='{$list5['item_name']}' value='{$list5['item_name']}'></td>";
echo "<td width='10%'><input type='text' size='7' id='item_partno$i' name='item_partno[$i]' value='{$list5['item_partno']}'></td>";
echo "<td width='15%'><textarea rows='4' cols='50' id='prod_description$i' name='prod_description[$i]'></textarea></td>";
echo "<td width='3%'><input size='1' type='text' name='item_quantity[]' id='item_quantity[]' value='{$list5['item_quantity']}' /></td>";
echo "<td width='3%'><input size='2' type='text' name='item_units[]' id='item_units[]' value='{$list5['item_units']}' readonly/></td>";
echo "<td width='4%'><input size='5' type='text' name='unitprice[]' id='unitprice[]' /></td>";
echo "<td width='8%'><input size='8' type='text' name='total[]' id='total[]' readonly class='total' /></td>";
echo "</tr>";
++$i;
}
echo '<input type="submit" value="--Save Data--" />';
</form>
Save.php is below:
$size = count($_POST['unitprice']);
$i = 0;
while ($i < $size) {
$sl= $_POST['sl'][$i];
$item_id= $_POST['item_id'][$i];
$item_name= $_POST['item_name'][$i];
$prod_description=$_POST['prod_description'][$i];
$prod_description= mysql_real_escape_string($prod_description);
$query = "INSERT INTO comparitive_st_sup SET tender_id='$tender_id', item_id='$item_id', ifmain='$ifmain', slno = '$sl',item_name = '$item_name',item_partno = '$item_partno',prod_description = '$prod_description',sup_itempartno = '$sup_itempartno',currency = '$currency_selected',slab_range= '$slab_range',qty = '$item_quantity',qty_sup = '$item_quantity_sup',item_units = '$item_units',item_units_sup = '$item_units_sup',unitprice = '$unitprice',total = '$total', total_inr='$total_inr', supplier_name='$supplier_name2' ";
mysql_query($query) or die ("Error in query: $query");
++$i;
}
Please find the HTML below:
<html>
<head>
<title>PRICE</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="javascript" type="text/javascript">
tinyMCE.init({
toolbar: false,
menubar: false,
mode: "textareas",
height: "150px",
width: "180px"
});
</script>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
</head>
<body>
<div id="wrapper">
<form name="cart" method="post" class="single" action="price_add_save.php?supplier_name=TE+Connectivity&tender_id=150596">
<div align="center">
<h3>TE Connectivity</h3>
<table style="border-collapse: collapse;" id="table" border="1" cellpadding="2" cellspacing="2" width="100%">
<thead>
<tr bgcolor="#E6E6FA">
<td width="4%">SlNo</td>
<td width="4%">Main Item</td>
<td width="10%">Item Name</td>
<td width="10%">Item Part No</td>
<td width="6%">Part No - Supplier</td>
<td width="4%">Slab Range</td>
<td width="3%">Qty</td>
<td width="4%">Qty Supplier</td>
<td width="3%">Units</td>
<td width="3%">Units Supplier</td>
<td width="4%">Unitprice</td>
<td width="6%">Total</td>
<td width="6%">Currency</td>
<td width="6%">Total INR</td>
</tr>
</thead>
<tbody>
<tr>
<td width="4%">
<input size="1" name="id[0]" value="0" readonly="readonly" type="hidden">
<input size="1" id="sl[0]" name="sl[0]" readonly="readonly" type="text">
<input size="1" id="item_id[0]" name="item_id[0]" value="0" readonly="readonly" type="hidden">
</td>
<td width="4%">
<select id="ifmain[0]" name="ifmain[0]">
<option selected="selected" value="Yes">Main Item</option>
<option value="No">Sub Item</option>
</select>
</td>
<td id="addinput" width="10%">
<input size="15" id="item_name0" name="item_name[0]" placeholder="" type="text">
</td>
<td width="10%">
<input size="7" id="item_partno0" name="item_partno[0]" type="text">
</td>
<td width="6%">
<input size="11" id="sup_itempartno0" name="sup_itempartno[0]" type="text">
</td>
<td width="4%">
<input size="3" class="slab_range" name="slab_range[]" id="slab_range[]" type="text">
</td>
<td width="3%">
<input size="1" data-validation="required" class="item_quantity" name="item_quantity[]" id="item_quantity[]" value="0" type="text">
</td>
<td width="4%">
<input size="1" data-validation="required" class="item_quantity_sup" name="item_quantity_sup[]" id="item_quantity_sup[]" type="text">
</td>
<td width="3%">
<input size="2" class="item_units" name="item_units[]" id="item_units[]" readonly="readonly" type="text">
</td>
<td width="3%">
<input size="2" data-validation="required" class="item_units_sup" name="item_units_sup[]" id="item_units_sup[]" type="text">
</td>
<td width="4%">
<input size="5" data-validation="required" class="unitprice" name="unitprice[]" id="unitprice[]" type="text">
</td>
<td width="8%">
<input size="8" name="total[]" id="total[]" readonly="readonly" class="total" type="text">
</td>
<td width="6%">
<select class="currency-select" data-validation="required" id="currency_change[]" name="currency_change[]">
<option selected="selected" value="">select</option>
<option value="USD" data-price="1">USD</option>
<option value="INR" data-price="67.434191">INR</option>
<option value="GBP" data-price="0.704985">GBP</option>
<option value="EUR" data-price="0.91118">EUR</option>
<option value="SGD" data-price="1.386987">SGD</option>
<option value="AUD" data-price="1.347597">AUD</option>
<option value="CAD" data-price="1.342118">CAD</option>
<option value="CHF" data-price="0.997145">CHF</option>
<option value="JPY" data-price="112.6934">JPY</option>
<option value="MYR" data-price="4.129541">MYR</option>
<option value="ZAR" data-price="15.43258">ZAR</option>
</select>
</td>
<td width="8%">
<input size="8" class="total1" id="total_inr[]" name="total_inr[]" type="text">
</td>
<input class="inrvalue" id="inrvalue" name="inrvalue" value="67.434191" type="hidden">
</tr>
</tbody>
<tbody>
<tr>
<td width="4%">
<input size="1" name="id[1]" value="937" readonly="readonly" type="hidden">
<input size="1" id="sl[1]" name="sl[1]" value="1" readonly="readonly" type="text">
<input size="1" id="item_id[1]" name="item_id[1]" value="937" readonly="readonly" type="hidden">
</td>
<td width="4%">
<select id="ifmain[1]" name="ifmain[1]">
<option selected="selected" value="Yes">Main Item</option>
<option value="No">Sub Item</option>
</select>
</td>
<td id="addinput" width="10%">
<input size="15" id="item_name1" name="item_name[1]" placeholder="Chlorophyll Meter" value="Chlorophyll Meter" type="text">
</td>
<td width="10%">
<input size="7" id="item_partno1" name="item_partno[1]" value=" SPAD 502 DL" type="text">
</td>
<td width="6%">
<input size="11" id="sup_itempartno1" name="sup_itempartno[1]" type="text">
</td>
<td width="4%">
<input size="3" class="slab_range" name="slab_range[]" id="slab_range[]" type="text">
</td>
<td width="3%">
<input size="1" data-validation="required" class="item_quantity" name="item_quantity[]" id="item_quantity[]" value="1" type="text">
</td>
<td width="4%">
<input size="1" data-validation="required" class="item_quantity_sup" name="item_quantity_sup[]" id="item_quantity_sup[]" type="text">
</td>
<td width="3%">
<input size="2" class="item_units" name="item_units[]" id="item_units[]" value="Nos" readonly="readonly" type="text">
</td>
<td width="3%">
<input size="2" data-validation="required" class="item_units_sup" name="item_units_sup[]" id="item_units_sup[]" type="text">
</td>
<td width="4%">
<input size="5" data-validation="required" class="unitprice" name="unitprice[]" id="unitprice[]" type="text">
</td>
<td width="8%">
<input size="8" name="total[]" id="total[]" readonly="readonly" class="total" type="text">
</td>
<td width="6%">
<select class="currency-select" data-validation="required" id="currency_change[]" name="currency_change[]">
<option selected="selected" value="">select</option>
<option value="USD" data-price="1">USD</option>
<option value="INR" data-price="67.434191">INR</option>
<option value="GBP" data-price="0.704985">GBP</option>
<option value="EUR" data-price="0.91118">EUR</option>
<option value="SGD" data-price="1.386987">SGD</option>
<option value="AUD" data-price="1.347597">AUD</option>
<option value="CAD" data-price="1.342118">CAD</option>
<option value="CHF" data-price="0.997145">CHF</option>
<option value="JPY" data-price="112.6934">JPY</option>
<option value="MYR" data-price="4.129541">MYR</option>
<option value="ZAR" data-price="15.43258">ZAR</option>
</select>
</td>
<td width="8%">
<input size="8" class="total1" id="total_inr[]" name="total_inr[]" type="text">
</td>
<input class="inrvalue" id="inrvalue" name="inrvalue" value="67.434191" type="hidden">
</tr>
</tbody>
</table>
</div>
<br>
<br>
<table>
<tbody>
<tr>
<td></td>
<td>
<input value="--Save Data--" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
window.onload = function() {
function calculateRowTotals(row) {
console.log("calculateRowTotals()", row);
var currency = row.find(".currency-select").val();
var conversionRate = row.find(".currency-select option[value=" + currency + "]").data("price");
var totalINR = row.find('.total').val();
//alert (totalINR);
//console.log(totalINR);
//console.log(conversionRate);
console.log("total1 => " + row.find('.total1').length);
//var newTotal = currency==="INR" ? totalINR : (totalINR * conversionRate / row.find('.inrvalue').val()).toFixed(3);
var newTotal = 0;
if (currency === "INR") {
newTotal = totalINR;
} else if (currency === "USD") {
newTotal = ((totalINR * row.find('.inrvalue').val()).toFixed(3));
} else {
newTotal = (((row.find('.inrvalue').val() / conversionRate) * totalINR).toFixed(3));
}
console.log("New total is " + newTotal + " & old one is " + row.find('.total1').val());
row.find('.total1').val(newTotal);
//row.find('.price_unit').val((newTotal/row.find('.qty').val()).toFixed(3));
}
$(document).ready(function() {
//$("select").change(function (event, processing) {
$(".currency-select").change(function(event, processing) {
console.log("A row changed", processing, event);
var row = $(this).closest('tr');
var table = row.closest('table');
var currency = $(this).val();
if (processing) {
// Calculate me
calculateRowTotals($(row));
} else {
// Calculate other if not processing yet
table.find("tr").each(function() {
$(this).find("select").val(currency).trigger("change", 1);
});
}
});
});
}
</script>
<script type="text/javascript">
$('#table :input').change(function() {
var $tr = $(this).closest('tr'),
$totInr = $tr.find('[name="total_inr[]"]'),
unitprice = +$tr.find('[name="unitprice[]"]').val() || 0,
qty = +$tr.find('[name="item_quantity_sup[]"]').val() || 0,
$currency = $tr.find('[name="currency_change[]"] option:selected'),
currency = $currency.val(),
inr = $('#inrvalue').val();
var total = unitprice * qty;
$tr.find('[name="total[]"]').val(total);
})
</script>
</div>
<script type="text/javascript">
$('form#cart').submit(function(e) {
$(this).children('input[type=submit]').attr('disabled', 'disabled');
});
</script>
</body>
</html>

select option not displaying correctly after .load ajax

I am loading a php page into a spefific div, using this code
function peopleEdit(id, currid) {
$("#people_edit").load( "people_edit.php?id="+currid );
return false;
}
There are 2 issues though.
the form displayed, has the option values out of the select box, and the option is not working.
the tinymce box is displayed but the data are out of the box.
the form is tested and is working properly before the ajax .load
here's the html of the form.
<form action="people.php" enctype="multipart/form-data" name="pelatesForm" id="pelatesForm" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="right">Τύπος</td>
<td width="80%"><label>
<select name="pelates_type_det" id="pelates_type_det" />
<option value="<?php echo $pelates_det_type ?>"><?php echo $pelates_det_type ?></option>
<option value="Πελάτης">Πελάτης</option>
<option value="Προμηθευτής">Προμηθευτής</option>
</select>
</label></td>
</tr>
<tr>
<td width="20%" align="right">Όνομα</td>
<td width="80%"><label>
<input name="pelates_first_name_det" type="text" id="pelates_first_name_det" size="64" value="<?php echo $pelates_det_first_name ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Επίθετο</td>
<td width="80%"><label>
<input name="pelates_last_name" type="text" id="pelates_last_name" size="64" value="<?php echo $pelates_det_last_name ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Τηλέφωνο - Σταθερό</td>
<td width="80%"><label>
<input name="pelates_phone" type="text" id="pelates_phone" size="64" value="<?php echo $pelates_det_phone ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Τηλέφωνο - Κινητό</td>
<td width="80%"><label>
<input name="pelates_cell" type="text" id="pelates_cell" size="64" value="<?php echo $pelates_det_cell ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Email</td>
<td width="80%"><label>
<input name="pelates_email" type="text" id="pelates_email" size="64" value="<?php echo $pelates_det_email ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Όνομα εταιρείας - Ιδιώτης</td>
<td width="80%"><label>
<input name="pelates_company" id="pelates_company" size="64" value="<?php echo $pelates_det_company ?>" />
</label>
</td>
</tr>
<tr>
<td width="20%" align="right">ΑΦΜ</td>
<td width="80%"><label>
<input name="pelates_afm" type="text" id="pelates_afm" size="64" value="<?php echo $pelates_det_afm ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">ΔΟΥ</td>
<td width="80%"><label>
<input name="pelates_doy" type="text" id="pelates_doy" size="64" value="<?php echo $pelates_det_doy ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Διεύθυνση</td>
<td width="80%"><label>
<input name="pelates_address" type="text" id="pelates_address" size="64" value="<?php echo $pelates_det_address ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Ταχυδρομικός κώδικας</td>
<td width="80%"><label>
<input name="pelates_tk" type="text" id="pelates_tk" size="64" value="<?php echo $pelates_det_tk ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Περιοχή</td>
<td width="80%"><label>
<input name="pelates_area" type="text" id="pelates_area" size="64" value="<?php echo $pelates_det_area ?>" />
</label></td>
</tr>
<tr>
<td width="20%" align="right">Σχόλια</td>
<td width="80%">
<textarea name="pelates_comments_det" type="text" class="tinymce" id="pelates_comments_det" size="64" /><?php echo $pelates_det_comments ?></textarea>
</td>
</tr>
<tr>
<td> </td>
<td><label>
<input name="thisID" type="hidden" value="<?php echo $targetID ?>" />
<input type="submit" name="submitpel" id="submitpel" value="Υποβολή" />
<input type="button" value="Άκυρο" onclick="return epistrofi('people_detailed','<?php echo $targetID ?>');" />
</label>
</td>
</tr>
</table>
</form>
any ideas of why is this happening?
You close your select :
<select name="pelates_type_det" id="pelates_type_det" />
Change to:
<select name="pelates_type_det" id="pelates_type_det">

How to add multiple input textfield values into db using php

How to insert multiple textfields value into mysqldb?
<?php
if(isset($_POST['save'])){
foreach($_POST['color'] as $key => $value)
{
if($color!="")
{
$color = $value['code'];
echo $color;
$rgb = hex2rgba($color);
$rgba = hex2rgba($color, 0.7);
/*echo $rgba;
echo $value['key'];
echo $value['code'];
echo $value['order_color'];*/
$sql = "INSERT INTO tbl_colors values('','$rgba','".$value['key']."','".$value['code']."','".$value['order_color']."')";
$rs = mysql_query($sql) or die("Bad Query==><br><br>$sql<br><br>".mysql_error());
}
}
?>
<form action="" method="post" name="recommend">
<tr>
<td><input type="text" value="" name="color[][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[][code]" class="email"></td>
<td><input type="text" value="" name="color[][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td><input type="text" value="" name="color[][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[][code]" class="email"></td>
<td><input type="text" value="" name="color[][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" name="save" value="Add Color" /></td>
</tr>
</form>
{
<?php
if(isset($_POST['save'])){
foreach($_POST['color'] as $key => $value)
{
$color = $value['code'];
echo $color;
$rgb = hex2rgba($color);
$rgba = hex2rgba($color, 0.7);
/*echo $rgba;
echo $value['key'];
echo $value['code'];
echo $value['order_color'];*/
$sql = "INSERT INTO tbl_colors values('','$rgba','".$value['key']."','".$value['code']."','".$value['order_color']."')";
$rs = mysql_query($sql) or die("Bad Query==><br><br>$sql<br><br>".mysql_error());
}
}
?>
<form action="" method="post" name="recommend">
<tr>
<td><input type="text" value="" name="color[1][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[1][code]" class="email"></td>
<td><input type="text" value="" name="color[1][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td><input type="text" value="" name="color[2][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[2][code]" class="email"></td>
<td><input type="text" value="" name="color[2][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" name="save" value="Add Color" /></td>
</tr>
</form>
}
Row1, Row2, Row3 are your table rows you need to name them to your table row.
<?php
if(isset($_POST['colorkey'])){
$colorkey = $_POST['colorkey'];
$colorcode = $_POST['colorkcode'];
$colorcode = $_POST['colororder'];
$sql = ("INSERT INTO tbl_colors (Row1, Row2, Row3) VALUES ('$colorkey', '$colorcode', '$colorcode')");
}
?>
<form action="" method="post" name="recommend">
<tr>
<td><input type="text" value="" name="colorkey" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="colorcode" class="email"></td>
<td><input type="text" value="" name="colororder" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td><input type="text" value="" name="colorkey" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="colorcode" class="email"></td>
<td><input type="text" value="" name="colororder" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" name="save" value="Add Color" /></td>
</tr>
</form>

MySQL table isn't updated but PHP echos a record added

I'm having a hard time figuring this out. Tried everything, yet nothing seems to work. I even have two similar pages and the other inserts and updates just fine but this has been giving me sleepless nights.
After filling form entries and submitting, there's a confirmation that the record has been added but nothing is inserted into the database table. This is supposed to be part of an app for a clinic to deal with maternity/anc/pnc but this problem affects only the anc files. The pnc part of it works pretty well.
I'm certain you guys can help me see exactly what I'm not doing right and I truly would appreciate any assistance. Right or wrong.
First here's the file that's supposed to insert the records, called submitanc.php:
#$cid= $_POST["cid"];
#$card= $_POST["card"];
#$date= $_POST["date"];
#$doctor= $_POST["doctor"];
#$riskfactor= $_POST["riskfactor"];
#$cycle= $_POST["cycle"];
#$lmp= $_POST["lmp"];
#$edd= $_POST["edd"];
#$gestationage= $_POST["gestationage"];
#$visit= $_POST["visit"];
#$parity= $_POST["parity"];
#$bp= $_POST["bp"];
#$height= $_POST["height"];
#$weight= $_POST["weight"];
#$gestation= $_POST["gestation"];
#$fhh= $_POST["fhh"];
#$sickling= $_POST["sickling"];
#$hb= $_POST["hb"];
#$hb36wk= $_POST["hb36wk"];
#$vdll= $_POST["vdll"];
#$pmtct= $_POST["pmtct"];
#$arv= $_POST["arv"];
#$tt= $_POST["tt"];
#$itw= $_POST["itw"];
#$ipt= $_POST["ipt"];
#$referredto= $_POST["referredto"];
#$diagnosis= $_POST["diagnosis"];
#$remark= $_POST["remark"];
require_once 'conn.php';
if (isset($_POST['submit']))
{
switch ($_POST['submit'])
{
case 'Add Record':
if (Trim($card) != "" and Trim($date) != "")
{
$query_insert = "Insert into `anc` (`Card Number`, `Date`, `Physician`, `Risk Factor`, `Cycle`, `LMP`, `Edd`, `Gestation Age`, `Visit`, `Parity`, `BP`, `Height`, `Weight`, `Gestation`, `FHH`, `Sickling`, `HB#Reg`, `Temp`, `VDLL`, `PMTCT`, `ARV`,`TT`,`IPT`,`ITW`,`Referred To`,`Diagnosis` `Remark`,`SFH`,`HIV`,`Hep B`,`PH`,`Urine`,`Presentation`,`Lie`)
VALUES ('$card', '$date', '$doctor', '$riskfactor', '$cycle', '$lmp', '$edd', '$gestationage', '$visit', '$parity', '$bp', '$height', '$weight', '$gestation', '$fhh', '$sickling', '$hb', '$temp', '$vdll', '$pmtct', '$arv','$tt','$ipt','$itw','$referredto','$diagnosis', '$remark','$sfh','$hiv','$hepb','$ph','$urine','$presentation','$lie')"; $result_insert = mysql_query($query_insert);
And here, I know its crazy, but this is the form page, called anc.php:
<form action="submitanc.php" method="post">
<fieldset id="fieldset">
<legend><b><font size="2" face="Tahoma" color="green">Ante-Natal Basics</font></b></legend>
<div align="left">
<TABLE width='99%' border='0' cellpadding='1' cellspacing='1' align='center' bordercolor="#005B00" id="">
<tr>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Date of Visit:</font></b>
</td>
<td>
<input type="hidden" size="20" name="card" value="<?php echo $card; ?>">
<input type="hidden" size="20" name="cid" value="<?php echo $idx; ?>">
<?php
if (!$idx)
{ ?>
<input id="inputField" type="text" size="20" name="date" value="<?php echo date('Y-m-d'); ?>">
<?php
} else
{ ?>
<input id="inputField" type="text" size="20" name="date" value="<?php echo $srow['Date']; ?>">
<?php } ?>
</td>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Name of Doctor/Midwife:</font></b>
</td>
<td>
<input type="text" size="20" name="doctor" value="<?php echo $srow['Physician']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Major Risk Factor:</font></b>
</td>
<td colspan='3'>
<textarea cols="40" rows="3" name="riskfactor"><?php echo $srow['Risk Factor']; ?></textarea>
</td>
</tr>
</table>
</fieldset>
<fieldset id="fieldset">
<legend><b><font size="2" face="Tahoma" color="green">Menstrual History</font></b></legend>
<div align="left">
<TABLE width='99%' border='0' cellpadding='1' cellspacing='1' align='center' bordercolor="#005B00" id="">
<tr>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Cycle:</font></b>
</td>
<td>
<input type="text" size="20" name="cycle" value="<?php echo $srow['Cycle']; ?>">
</td>
<td width="20%">
<b><font face="Verdana" style="font-size: 9pt">Last Mentrual Period (L.M.P):</font></b>
</td>
<td>
<input type="text" size="20" name="lmp" value="<?php echo $srow['LMP']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Expected Delivery Date (E.D.D):</font></b>
</td>
<td>
<input type="text" size="20" name="edd" value="<?php echo $srow['EDD']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Gestation Age at Booking:</font></b>
</td>
<td>
<input type="text" size="20" name="gestationage" value="<?php echo $srow['Gestation Age']; ?>">
</td>
</tr>
</TABLE>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#dcdfdf" width="100%" id="AutoNumber1">
<?php
echo "<TR bgcolor='#9ff4ae'><TH><b><u>LMP </b></u> </TH><TH><b><u>EDD </b></u> </TH><TH><b><u>EGA to Date</b></u> </TH></TR>";
$querya="SELECT `ID`,`Card Number`,`Date`,`LMP`,`EDD`,`Gestation Age` FROM `anc` WHERE `Card Number`='$card' order by `Date` desc";
$resulta=mysql_query($querya);
while(list($idx,$cart,$date,$lmp,$edd,$ega)=mysql_fetch_row($resulta))
{
echo "<TR><TH><a title='Click on this to amend it' href = 'anc.php?idx=" . $idx . "&card=" . $cart . "&dat=" . $date . "'>$lmp </a> </TH><TH> $edd </TH><TH>$ega </font></TH></TR>";
}
?>
</table>
</fieldset>
<fieldset id="fieldset">
<legend><b><font size="2" face="Tahoma" color="green">Ante-Natal Examination</font></b></legend>
<div align="left">
<TABLE width='99%' border='0' cellpadding='1' cellspacing='1' align='center' bordercolor="#005B00" id="">
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Blood Pressure:</font></b>
</td>
<td>
<input type="text" size="20" name="bp" value="<?php echo $srow['BP']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Parity:</font></b>
</td>
<td>
<input type="text" size="20" name="parity" value="<?php echo $srow['Parity']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Weight:</font></b>
</td>
<td>
<input type="text" size="20" name="weight" value="<?php echo $srow['Weight']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Temperature:</font></b>
</td>
<td>
<input type="text" size="20" name="temp" value="<?php echo $srow['Temp']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Visit:</font></b>
</td>
<td>
<select size="1" name="visit">
<?php
echo '<option selected>' . $srow['Visit'] . '</option>';
echo '<option>New Visit</option>';
echo '<option>Returning Visit</option>';
?>
</select>
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Height:</font></b>
</td>
<td>
<input type="text" size="20" name="height" value="<?php echo $srow['Height']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Gestational Age:</font></b>
</td>
<td>
<input type="text" size="20" name="gestation" value="<?php echo $srow['Gestation']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">SFH:</font></b>
</td>
<td>
<input type="text" size="20" name="sfh" value="<?php echo $srow['SFH']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Sickling:</font></b>
</td>
<td>
<input type="text" size="20" name="sickling" value="<?php echo $srow['Sickling']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Hb:</font></b>
</td>
<td>
<input type="text" size="20" name="hb" value="<?php echo $srow['HB#Reg']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">HIV:</font></b>
</td>
<td>
<input type="text" size="20" name="hiv" value="<?php echo $srow['HIV']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Hep B:</font></b>
</td>
<td>
<input type="text" size="20" name="hepb" value="<?php echo $srow['HepB']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">PH:</font></b>
</td>
<td>
<input type="text" size="20" name="ph" value="<?php echo $srow['PH']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Urine:</font></b>
</td>
<td>
<input type="text" size="20" name="urine" value="<?php echo $srow['Urine']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Presentation:</font></b>
</td>
<td>
<input type="text" size="20" name="presentation" value="<?php echo $srow['Presentation']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Lie:</font></b>
</td>
<td>
<input type="text" size="20" name="lie" value="<?php echo $srow['Lie']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">FHR:</font></b>
</td>
<td>
<input type="text" size="20" name="fhh" value="<?php echo $srow['FHH']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">Sickling:</font></b>
</td>
<td>
<input type="text" size="20" name="sickling" value="<?php echo $srow['Sickling']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">VDLL:</font></b>
</td>
<td>
<input type="text" size="20" name="vdll" value="<?php echo $srow['VDLL']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">PMTCT:</font></b>
</td>
<td>
<?php
$sqlv2 = "SELECT `val`,`type` FROM `booln` ORDER BY `type` desc";
$result_v2 = mysql_query($sqlv2,$conn) or die('Could not list; ' . mysql_error());
$v2=$srow['PMTCT'];
while ($rows = mysql_fetch_array($result_v2))
{
echo ' <input type="radio" class="radio" align="left" id="v2_' . $rows['val'] . '" name="pmtct" value="' . $rows['val'] . '" ';
if ($rows['val'] == $v2)
{
echo 'checked="checked" ';
}
echo '/>' . $rows['type'] . "\n";
}
?>
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">ARV:</font></b>
</td>
<td>
<input type="text" size="20" name="arv" value="<?php echo $srow['ARV']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">TT:</font></b>
</td>
<td>
<input type="text" size="20" name="tt" value="<?php echo $srow['TT']; ?>">
</td>
</tr>
<tr>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">ITW:</font></b>
</td>
<td>
<input type="text" size="20" name="itw" value="<?php echo $srow['ITW']; ?>">
</td>
<td width="10%">
<b><font face="Verdana" style="font-size: 9pt">IPT:</font></b>
</td>
<td>
<?php
$sqlv2 = "SELECT `val`,`type` FROM `booln` ORDER BY `type` desc";
$result_v2 = mysql_query($sqlv2,$conn) or die('Could not list; ' . mysql_error());
$v2=$srow['IPT'];
while ($rows = mysql_fetch_array($result_v2))
{
echo ' <input type="radio" class="radio" align="left" id="v2_' . $rows['val'] . '" name="ipt" value="' . $rows['val'] . '" ';
if ($rows['val'] == $v2)
{
echo 'checked="checked" ';
}
echo '/>' . $rows['type'] . "\n";
}
?>
</td>
</tr>
<tr>
<td width="15%">
<b><font face="Verdana" style="font-size: 9pt">Refered To:</font></b>
</td>
<td>
<input type="text" size="20" name="referredto" value="<?php echo $srow['Referred To']; ?>">
</td>
<td width="15%">
<b><font face="Verdana" style="font-size: 9pt">Diagnosis:</font></b>
</td>
<td>
<input type="text" size="20" name="diagnosis" value="<?php echo $srow['Diagnosis']; ?>">
</td>
</tr>
<tr>
<td width="14%">
<b><font face="Verdana" style="font-size: 9pt">Remark:</font></b>
</td>
<td colspan='3'>
<textarea cols="40" rows="3" name="remark"><?php echo $srow['Remark']; ?></textarea>
</td>
</tr>
<tr>
<td width="10%">
<?php
if (!$idx)
{ ?>
<input type="submit" value="Add Record" name="submit">
<?php
} else
{ ?>
<input type="submit" value="Update Record" name="submit">
<?php } ?>
</td>
</tr>
</TABLE>
</form>
</fieldset>
<fieldset style="padding: 2">
<legend><b><font size="2" face="Tahoma" color="green">History of ANC</font></b></legend>
<b><font color="#FF0000" style="font-size: 8pt"><?php echo $tval ; ?></font></b>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#dcdfdf" width="99%" id="AutoNumber1">
<?php
echo "<TR bgcolor='#9ff4ae'><TH><b><u>Date of Visit </b></u> </TH><TH><b><u>Weight </b></u> </TH><TH><b><u>BP</b></u> </TH><TH><b><u>SFH </b></u> </TH><TH><b><u>Urine </b></u> </TH><TH><b><u>FHR </b></u> </TH></TR>";
$query="SELECT `ID`,`Card Number`,`Date`,`Weight`,`BP`,`SFH`,`Urine`,`FHR` FROM `anc` WHERE `Card Number`='$card' order by `Date` desc";
$result=mysql_query($query);
while(list($idx,$cart,$date,$wt,$bp,$sfh,$urine,$fhr)=mysql_fetch_row($result))
{
echo "<TR><TH><a title='Click on this to amend it' href = 'anc.php?idx=" . $idx . "&card=" . $cart . "&dat=" . $date . "'>$date </a> </TH><TH> $wt </TH><TH>$bp </font></TH><TH>$sfh </TH><TH>$urine </TH><TH>$fhr </TH></TR>";
}
?>
</table>
</fieldset>
its better to use
mysql_escape_string($_POST['fieldname']);
and echo that query and check in mysql
$query_insert = "Insert into `anc` (`Card Number`, `Date`, `Physician`, `Risk Factor`, `Cycle`, `LMP`, `Edd`, `Gestation Age`, `Visit`, `Parity`, `BP`, `Height`, `Weight`, `Gestation`, `FHH`, `Sickling`, `HB#Reg`, `Temp`, `VDLL`, `PMTCT`, `ARV`,`TT`,`IPT`,`ITW`,`Referred To`,`Diagnosis` `Remark`,`SFH`,`HIV`,`Hep B`,`PH`,`Urine`,`Presentation`,`Lie`)
VALUES ('$card', '$date', '$doctor', '$riskfactor', '$cycle', '$lmp', '$edd', '$gestationage', '$visit', '$parity', '$bp', '$height', '$weight', '$gestation', '$fhh', '$sickling', '$hb', '$temp', '$vdll', '$pmtct', '$arv','$tt','$ipt','$itw','$referredto','$diagnosis', '$remark','$sfh','$hiv','$hepb','$ph','$urine','$presentation','$lie')"; $result_insert = mysql_query($query_insert);
$res=mysql_query($query_insert);
if(!$res){
die('Could not enter data: ' . mysql_error());
}
//Confirm success with the username
echo '<p><b>Your MSG</b></p>';
}
then give the successfull msg . and figure where its goin wrong

Input field added through javascript not in PHP $_POST variable. How to fix this?

I have a form inside an html table.
I am dynamically adding input fields to a form through jquery. When I took var dump while submitting the form, the $_POST array does not have the added fields. Why is it happening?
Here is how my js looks like:
$('#add-more-del-areas').live('click',function(e){
var del_area_count = $('[name=number_of_delivery_areas]').val();
var new_count = (parseInt(del_area_count)+1);
var tr_html = '<tr>'+
'<td style="padding:10px 0px 0px 10px;"><strong>Delivery Area '+new_count+'</strong></td>'+
'<td>'+
'<input name="d_area'+new_count+'" type="text" size="50" value=""/>'+
'<div class="area-display-container" id="test'+new_count+'-display"></div>'+
'<div>'+
'<input class="auto-suggest-input" type="text" autocomplete="off" id="test'+new_count+'"/>'+
'<div class="test-content" id="test'+new_count+'-content"></div>'+
'</div>'+
'</td>'+
'</tr>'+
'<tr id="del_area-'+new_count+'" bgcolor="#FF9933">'+
'<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area '+new_count+'</strong></td>'+
'<td><input name="m_order'+new_count+'" type="text" size="50" value="0"></td>'+
'</tr>';
//$('#del_area-'+del_area_count).after(tr_html);
$(tr_html).insertAfter('#del_area-'+del_area_count);
big_cms.auto_suggest_({id: 'test'+new_count,input_field: 'd_area'+new_count});
$('[name=number_of_delivery_areas]').val(new_count);
e.preventDefault();
});
Though html is pathetic and too long still, here it is:
<table width="840" border="0" cellpadding="0" cellspacing="0" style="border: #57414D 4px Solid; margin:auto;">
<tr>
<td height="20px" bgcolor="#57414D" align="center" colspan="2"><span style="font-family:arial; font-size:13px; color:#ffffff"><b>You can add/edit Restaurant/Management content here!!</b></span></td>
</tr>
<?php
if ($bgclass == "bgExtraLightGray")
$bgclass = "bgWhite";
else
$bgclass = "bgExtraLightGray";
?>
<form name="frmCatPopup" method="POST" enctype="multipart/form-data" onSubmit="return ValidateContactForm();">
<tr align="center" bgcolor="#FF9933" class="<?php echo($bgclass); ?>">
<td colspan="2" class="note"> <?php echo($errMsg); ?></td>
</tr>
<tr>
<td width="40%" class="heading1" style="padding-left:10px"><strong>Register Name</strong></td>
<td width="60%" style="padding-bottom:4px;"><select name="name" class="restar_txtbox" style="width:326px;">
<?php
$quer_l="select * from ".$tableprefix."restaurant_sign_up";
$cmd_l=mysql_query($quer_l);
while($res_l=mysql_fetch_array($cmd_l))
{
?>
<option value="<?php echo $res_l['fld_id']; ?>" <?php if($rs['signup_id']==$res_l['fld_id']) echo"selected";?>><?php echo $res_l['fld_contact_person']; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr bgcolor="#FF9933">
<td width="40%" class="heading1" style="padding-left:10px"><strong>Restaurant Name</strong></td>
<td><input type="text" name="rest_name" size="50" value="<?php echo $rs['fld_name'];?>"/></td>
</tr>
<tr>
<td class="heading1" style="padding:4px 0 4px 10px;"><strong>Address</strong></td>
<td style="padding:4px 0 4px 0;">
<textarea rows="3" cols="38" name="address" id="address" value="<?php echo($rs["fld_address"]); ?>" size="50">
<?php echo($rs["fld_address"]); ?>
</textarea>
</td>
</tr>
<tr bgcolor="#FF9933">
<td class="heading1" style="padding-left:10px"><strong>Location</strong></td>
<td>
<select name="loc" style="width:326px;" ><!--onchange="locat(this.value)"-->
<option>Select Location</option>
<?php
$quer_l="select * from ".$tableprefix."location where location_status='1'";
$cmd_l=mysql_query($quer_l);
while($res_l=mysql_fetch_array($cmd_l))
{
?>
<option value="<?php echo $res_l['location_id']; ?>" <?php if($rs['location_id']==$res_l['location_id']) echo"selected";?>><?php echo $res_l['name']; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>Area</strong></td>
<td style="padding:4px 0 4px 0;">
<?php /*?><div id="area"><select name="area" style="width:326px;">
<option value="asap">Select Location First</option>
</select>
</div><?php */?>
<select name="area" style="width:326px;">
<?php
$quer_a="select * from ".$tableprefix."area where status='1'";
$cmd_a=mysql_query($quer_a);
while($res_a=mysql_fetch_array($cmd_a))
{
?>
<option value="<?php echo $res_a['area_id']; ?>" <?php if($rs['area_id']==$res_a['area_id']) echo"selected";?>><?php echo $res_a['area_name']; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding-left:10px"><strong>Opening Time</strong></td>
<td><input name="openingtime_start" type="text" id="openingtime_start" value="
<?php
$q1=$rs["fld_openingtime_start"];
$q=strlen($rs["fld_openingtime_start"]);
$S=substr("$q1","-$q","-2");
$S4=substr("$q1","-2","2");
echo $S;
?>">
<select name="start">
<option value="am" <?php if($S4=="am"){echo "selected";}?>>am</option>
<option value="pm" <?php if($S4=="pm"){echo "selected";}?>>pm</option>
</select>
</td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>Closing Time</strong></td>
<td style="padding:4px 0 4px 0;">
<input name="closingtime_start" type="text" class="restar_txtbox" id="closingtime_start" value="
<?php
$q6=$rs["fld_closingtime_start"];
$q7=strlen($rs["fld_closingtime_start"]);
$S3=substr("$q6","-$q7","-2");
$S4=substr("$q6","-2","2");
echo $S3;
?>">
<select name="end">
<option value="am"<?php if($S4=="am"){echo "selected";}?>>am</option>
<option value="pm" <?php if($S4=="pm"){echo "selected";}?>>pm</option>
</select>
</td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding:4px 0 4px 10px;"><strong>Opening Time</strong></td>
<td style="padding:4px 0 4px 0;">
<input name="openingtime_start1" type="text" class="restar_txtbox" id="openingtime_start1" value="
<?php
$q4=$rs["fld_openingtime_start1"];
$q5=strlen($rs["fld_openingtime_start1"]);
$S2=substr("$q4","-$q5","-2");
$S4=substr("$q4","-2","2");
echo $S2;
?>">
<select name="start1">
<option value="am" <?php if($S4=="am"){echo "selected";}?>>am</option>
<option value="pm" <?php if($S4=="pm"){echo "selected";}?>>pm</option>
</select>
</td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>Closing Time</strong></td>
<td style="padding:4px 0 4px 0;">
<input name="closingtime_start1" type="text" class="restar_txtbox" id="closingtime_start1" value="
<?php
$q2=$rs["fld_closingtime_start1"];
$q3=strlen($rs["fld_closingtime_start1"]);
$S1=substr("$q2","-$q3","-2");
$S4=substr("$q4","-2","2");
echo $S1;
?>">
<select name="end1">
<option value="am" <?php if($S4=="am"){echo "selected";}?>>am</option>
<option value="pm" <?php if($S4=="pm"){echo "selected";}?>>pm</option>
</select>
</td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding-left:10px"><strong>Delivery Fee</strong></td>
<td>
<input type="text" name="delivery_fee" value="<?php echo($rs["fld_deliveryfee"]); ?>" size="50">
</td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>Cuisines</strong></td>
<td style="padding:4px 0 4px 0;">
<select name="cuisines[]" id="cuisines[]" style="width:326px;" multiple="multiple">
<?php
$quer_l="select * from ".$tableprefix."cuisines where status='1'";
$cmd_l=mysql_query($quer_l);
$allCuisines = array();
while($row = mysql_fetch_assoc($cmd_l))
{
$allCuisines[] = $row;
}
//[BIG-3] In case there are multiple cuisines selected, they were not being pulled back from DB for display at frontend.
$cuisineIds = explode(',',$rs['fld_cuisines']); // In the $cuisineIds, all the cuisines selected from DB get stored
foreach( $allCuisines as $res_l) //Looping on all cuisines as they all need to be echoed once, as well as comparing the condition for a match to the Cuisines originally associated with restaurant
{
?>
<option value="<?php echo $res_l['cuisines_id']; ?>"
<?php
foreach ( $cuisineIds as $cuisId )
{
if($cuisId ==$res_l['cuisines_id'])
echo"selected";
}
?> >
<?php echo $res_l['cuisines_name']; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td style="padding-left:10px"><strong>Pure Veg</strong></td>
<td>
<input type="checkbox" name="veg_flag"
<?php
if(isSet($rs["veg_flag"]) && $rs['veg_flag']==1)
echo("checked='checked'");
?> value="1"/>
</td>
</tr>
<!--</td> </tr> -->
<tr bgcolor="#FF9933">
<td style="padding-left:10px"><strong>Min Order</strong></td>
<td>
<input type="text" name="min_order" value="
<?php echo($rs["fld_minorder"]); ?>" size="50"/>
</td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>Phone</strong></td>
<td style="padding:4px 0 4px 0;"><input name="phone" type="text" id="phone" size="50" value="<?php echo($rs["fld_phone"]); ?>"></td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding-left:10px"><strong>Upload 1</strong></td>
<td><input name="photos" type="file" size="38" id="photos" /></td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>upload 2</strong></td>
<td style="padding:4px 0 4px 0;"><input name="videos" type="file" id="videos" /></td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding-left:10px"><strong>Rating</strong></td>
<td><input name="rating" type="text" id="rating" value="<?php echo($rs["fld_rating"]); ?>" size="50"></td>
</tr>
<!--</td></tr> -->
<tr bgcolor="#fff001">
<td class="heading1" style="padding-left:10px"><strong>Restaurent Close Day</strong></td>
<td>
<select name="day" style="width:200px;" ><!--onchange="locat(this.value)"-->
<option value="0">Select Day</option>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
<option value="6">Saturday</option>
<option value="7">Sunday</option>
</select>
</td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>Description</strong></td>
<td style="padding:4px 0 4px 0;"><textarea name="desc" type="text" id="desc" cols="38" rows="3" ><?php echo($rs["fld_desc"]); ?></textarea></td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding-left:10px"><strong>Info</strong></td>
<td><textarea name="info" type="text" id="info" cols="38" rows="3" > <?php echo($rs["fld_info"]); ?></textarea></td>
</tr>
<tr>
<td style="padding:4px 0 4px 10px;"><strong>Specilialities</strong></td>
<td style="padding:4px 0 4px 0;"><input type="text" name="specialities" value="<?php echo($rs['fld_specialities']) ?>" size="50" /></td>
</tr>
<tr bgcolor="#FF9933" >
<td style="padding-left:10px"><strong>Delivery Time</strong></td>
<td><input name="delivery_time" type="text" id="delivery_time" size="50" value="<?php echo($rs["fld_deliverytime"]); ?>"></td>
</tr>
<tr>
<td style="padding:10px 0px 0px 10px;"><strong>Tax</strong></td>
<td><input name="tax" type="text" id="tax" size="50" value="<?php echo($rs["fld_tax"]); ?>"></td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Cost For One</strong></td>
<td><input name="cost" type="text" id="cost" size="50" value="<?php echo($rs["fld_cost"]); ?>"></td>
</tr>
<tr>
<td style="padding-left:10px"><strong>Packaging Charge</strong></td>
<td><input name="p_charge" type="text" size="50" value="<?php echo($rs["p_charge"]); ?>"></td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Label for Tax</strong></td>
<td><input name="label_t" type="text" size="50" value="<?php echo($rs["label_t"]); ?>"></td>
</tr>
<?php
if(isset($_GET['fld']))
{
$delivery_area_data = Task::getDeliveryAreaData($_GET['fld']);
$no_of_del_areas = sizeof($delivery_area_data);
if($no_of_del_areas > 0)
{
echo '<tr><td><input type="hidden" name="number_of_delivery_areas" value="'.$no_of_del_areas.'"/></td></tr>';
for($i=1;$i<=$no_of_del_areas;$i++)
{
$min_id = $i;
$min_order = $delivery_area_data[$i]['min_order'];
$area_id_str = implode(',',$delivery_area_data[$i]['area_ids']);
$area_name_str = '';
$j = 0;
foreach($delivery_area_data[$i]['area_names'] as $name)
{
$tmp_area_id = $delivery_area_data[$i]['area_ids'][$j];
$area_name_str .= '<span class="area-label" id="test'.$min_id.'-area-'.$tmp_area_id.'">
'.$name.'
<span class="test'.$min_id.'-delete-area delete-x" id="delete-area-'.$tmp_area_id.'">X</span>
</span>';
$j++;
}
echo '<tr>
<td style="padding:10px 0px 0px 10px;"><strong>Delivery Area '.$min_id.'</strong></td>
<td>
<input name="d_area'.$min_id.'" type="text" size="50" autocomplete="off" value="'.$area_id_str.'"/>
<div class="area-display-container" id="test'.$min_id.'-display">'.$area_name_str.'</div>
<div>
<input class="auto-suggest-input" type="text" autocomplete="off" id="test'.$min_id.'"/><br/>
<div class="test-content" id="test'.$min_id.'-content"></div>
</div>
</td>
</tr>
<tr id="del_area-'.$min_id.'" bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area '.$min_id.'</strong></td>
<td><input name="m_order'.$min_id.'" type="text" size="50" value="'.$min_order.'"></td>
</tr>
';
}
echo '<tr>
<td>
<button id="add-more-del-areas">Add more</button>
</td>
</tr>';
}
else
{
?>
<tr>
<td style="padding:10px 0px 0px 10px;"><strong>Delivery Area 1</strong></td>
<td>
<input name="d_area1" type="text" size="50" autocomplete="off" value=""/>
<div class="area-display-container" id="test1-display"></div>
<div>
<input class="auto-suggest-input" type="text" autocomplete="off" id="test1"/><br/>
<div class="test-content" id="test1-content"></div>
</div>
</td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area 1</strong></td>
<td><input name="m_order1" type="text" size="50" value=""/></td>
</tr>
<tr>
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery area 2</strong></td>
<td>
<input name="d_area2" type="text" size="50" value=""/>
<div class="area-display-container" id="test2-display"></div>
<div>
<input class="auto-suggest-input" type="text" autocomplete="off" id="test2"/>
<div class="test-content" id="test2-content"></div>
</div>
</td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area 2</strong></td>
<td><input name="m_order2" type="text" size="50" value=""/></td>
</tr>
<tr >
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery area 3</strong></td>
<td>
<input name="d_area3" type="text" size="50" value=""/>
<div class="area-display-container" id="test3-display"></div>
<div>
<input class="auto-suggest-input" type="text" autocomplete="off" id="test3"/><br/>
<div class="test-content" id="test3-content"></div>
</div>
</td>
</tr>
<tr id="del_area-3" bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area 3</strong></td>
<td><input name="m_order3" type="text" size="50" value=""/></td>
</tr>
<tr>
<td>
<button id="add-more-del-areas">Add more</button>
</td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td style="padding:10px 0px 0px 10px;"><strong>Delivery Area 1</strong></td>
<td>
<input name="d_area1" type="text" size="50" autocomplete="off" value=""/>
<div class="area-display-container" id="test1-display"></div>
<div>
<input class="auto-suggest-input" type="text" autocomplete="off" id="test1"/><br/>
<div class="test-content" id="test1-content"></div>
</div>
</td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area 1</strong></td>
<td><input name="m_order1" type="text" size="50" value="<?php //echo($rs["m_order1"]); ?>"></td>
</tr>
<tr>
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery area 2</strong></td>
<td>
<input name="d_area2" type="text" size="50" value=""/>
<div class="area-display-container" id="test2-display"></div>
<div>
<input class="auto-suggest-input" type="text" autocomplete="off" id="test2"/>
<div class="test-content" id="test2-content"></div>
</div>
</td>
</tr>
<tr bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area 2</strong></td>
<td><input name="m_order2" type="text" size="50" value="<?php //echo($rs["m_order2"]); ?>"></td>
</tr>
<tr >
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery area 3</strong></td>
<td>
<input name="d_area3" type="text" size="50" value=""/>
<div class="area-display-container" id="test3-display"></div>
<div>
<input class="auto-suggest-input" type="text" autocomplete="off" id="test3"/><br/>
<div class="test-content" id="test3-content"></div>
</div>
</td>
</tr>
<tr id="del_area-3" bgcolor="#FF9933">
<td style="padding:10px 0px 0px 10px;"><strong>Dilivery charges for area 3</strong></td>
<td><input name="m_order3" type="text" size="50" value="<?php //echo($rs["m_order3"]); ?>"></td>
</tr>
<tr>
<td>
<button id="add-more-del-areas">Add more</button>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="9" align="center" style="padding-top:5px">
<input type="submit" value="Save" name="btnSave" />
<input type="button" value="cancel">
</td>
</tr>
</form>
</table>
<div class="clr"></div>
</div>
</div>
<div class="restar_bottom"></div>
</div>
<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="cms.js"></script>
</body>
</html>
The HTML is invalid.
You cannot have a form inside a <table> but outside a <td> or <th> that is part of that table.
Some browsers error correct by moving the form somewhere it is valid (while leaving all the controls behind).
Use a validator to find this sort of markup error.

Categories