Multiple checkbox to a sentence before insert to mysql - php

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

Related

Having issue in my application form download

Having issue in my application form download.My issue is.once the form is submitted my java script code is not submitting the form to another page.page name is app_print.php.I have implemented js code in php.once every thing is correct.the app_print.php goes to download section.I have hosted in my webserver. Here is the link. http://lisieuxcbsekovai.com/application.php
Here is my code:
application.php
<form action="" method="post" name="application">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="3">
<?php
if(isset($_POST['application']))
{
unset($_POST['application']);
if(isset($rep))
{
if($rep=='sus')
{
?>
<div class="sus cl"><img class="pa" src="controller/image/btn/tick_circle.png"/><?php echo $msg;?><a style="margin:0px 0px 0px 0px;" href="javascript:void(0);"><img id="close" src="controller/image/btn/cross_grey_small.png"/></a></div>
<?php
}
else if($rep=='fld')
{
?>
<div class="error cl"><img class="pa" src="controller/image/btn/cross_circle.png"/><?php echo $msg;?><img id="close" src="controller/image/btn/cross_grey_small.png"/></div>
<?php
}
else if($rep=='atn')
{
?>
<div class="atn cl"><img class="pa" src="controller/image/btn/exclamation.png"/><?php echo $msg;?><img id="close" src="controller/image/btn/cross_grey_small.png"/></div>
<?php
}
}
}
?>
</td>
</tr>
<tr>
<th class="lft_col" colspan="3" style="color:#DB0009">APPLICATION FORM</th>
</tr>
<tr>
<td class="red">1.</td>
<th class="lft_col"><label>Name of the child<span class="red">*</span><br/><span style="font-size:11px;">(In Block letter)</span></label></th>
<td><input class="text" type="text" name="name" placeholder="Enter your Name" required value=""/></td>
</tr>
<tr>
<td class="red">2.</td>
<th class="lft_col"><label>Sex</label><span class="red">*</span></th>
<td>
<select class="select_2" name="sex" required>
<option value="">---Select---</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
</td>
</tr>
<tr>
<td class="red">3.</td>
<th class="lft_col"><label>Name of Parents<span class="red">*</span></label></th>
<td>
<table style="text-align:left;" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="red">i.</td>
<th class="lft_col">Father Name</th>
<td><input class="text" type="text" name="father" placeholder="Your Father/Guardian Name" required value=""/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="red">ii.</td>
<th class="lft_col">Mother Name</th>
<td><input class="text" type="text" name="mother" placeholder="Your Mother Name" required value=""/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="red">4.</td>
<th class="lft_col"><label>Address for <br/>communication<span class="red">*</span><label></th>
<td><textarea class="text" rows="10" placeholder="Your Communication Address." required name="address"></textarea></td>
</tr>
<tr>
<td class="red">5.</td>
<th class="lft_col">Contact No<span class="red">*</span></th>
<td><input class="text" type="text" name="mobile" placeholder="Mobile:+91 999999999" required value=""/></td>
</tr>
<tr>
<td class="red">6.</td>
<th class="lft_col"><label>Occupation of <br/>Parents with details<span class="red">*</span></label></th>
<td>
<table style="text-align:left;" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="red">i.</td>
<th class="lft_col"><label>Father Occupation</label></th>
<td><input class="text" type="text" name="father_occ" placeholder="Your Father/Guardian Occupation details" required value=""/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="red">ii.</td>
<th class="lft_col"><label>Mother Occupation</label></th>
<td><input class="text" type="text" name="mother_occ" placeholder="Your Mother Occupation details" required value=""/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="red">7.</td>
<th class="lft_col"><label>Date of Birth<span class="red">*</span><br/><span style="font-size:11px;">(as per Birth certificate)</span></label></th>
<td><input class="text" type="date" name="dob" placeholder="Your Date of Birth" required value=""/></td>
</tr>
<tr>
<td class="red">8.</td>
<th class="lft_col"><label>No of Year & Months that will <br/>be Completed as on June 1st<span class="red">*</span></label></th>
<td><input class="text" type="text" name="age" placeholder="Your Age (YYYY/MM/DD)" required value=""/></td>
</tr>
<tr>
<td class="red">9.</td>
<th class="lft_col"><label>Religion & Caste<span class="red">*</span><br/><span style="font-size:11px;">for Statistical purpose only</span></label></th>
<td><input class="text" type="text" name="religion" placeholder="Your Religion & Caste" required value=""/></td>
</tr>
<tr>
<td colspan="2"> </td>
<td class="lft_col">
<input class="btn" type="submit" name="application" value="Submit"/>
<input class="btn" onClick="javascript:window.location='application.php'" type="button" name="Cancel" value="Cancel"/>
</td>
</tr>
</table>
</form>
application.php
if(isset($_POST['application']))
{
$name=$_POST['name'];
$sex=$_POST['sex'];
$father=$_POST['father'];
$mother=$_POST['mother'];
$address=$_POST['address'];
$mobile=$_POST['mobile'];
$father_occ=$_POST['father_occ'];
$mother_occ=$_POST['mother_occ'];
$dob=$_POST['dob'];
$age=$_POST['age'];
$religion=$_POST['religion'];
date_default_timezone_set('Asia/Kolkata');
$cur_date = date('m/d/Y h:i:s a', time());
if($name!=''&&$sex!=''&&$father!=''&&$mother!=''&&$address!=''&&$mobile!=''&&$father_occ!=''&&$mother_occ!=''&&$dob!=''&&$age!=''&&$religion!='')
{
$con_qry=mysql_query("insert into application (name,sex,father,mother,address,mobile,father_occ,mother_occ,dob,age,religion,cur_date) values('".$name."','".$sex."','".$father."','".$mother."','".$address."','".$mobile."','".$father_occ."','".$mother_occ."','".$dob."','".$age."','".$religion."','".$cur_date."')");
if($con_qry)
{
$rep="sus";
$msg='Your application is downloaded, you can print the application from your download path.';
echo "<script type='text/javascript'>var url='app_print.php?id=$cur_date&c_name=$name';window.open(url)</script>";
}
else
{
$rep="fld";
$msg='Registeration Faild.';
}
}
}
?>
my app_print.php:
if((isset($_GET['id']))&&(isset($_GET['c_name'])))
{
$print=mysql_query("select * from application where name='".$_GET['c_name']."' and cur_date='".$_GET['id']."'");
$p_r=mysql_num_rows($print);
if($p_r>0)
{
$print_val=mysql_fetch_array($print);
$aid=$print_val['aid'];
$name=$print_val['name'];
$sex=$print_val['sex'];
$father=$print_val['father'];
$mother=$print_val['mother'];
$address=$print_val['address'];
$mobile=$print_val['mobile'];
$father_occ=$print_val['father_occ'];
$mother_occ=$print_val['mother_occ'];
$dob=$print_val['dob'];
$age=$print_val['age'];
$religion=$print_val['religion'];
$cur_date =$print_val['cur_date'];
header("Content-Type: application/download");
header("Content-Type: application/msword");
header('content-Disposition: attachment; filename='.$name.' Application'.'.doc');
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>LISIEUX - APPLICATION FORM</title>
</head>
<body>
<form action="" method="post" name="app_print">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="3" style="text-align:center;"><label><b style="font-size:29px;">Lisieux CMI Public School</b></label><br/><label>(CBSE Syllabus)</label><br/><label>Lisieux Road,Saravanampatti,Viswasapuram,Coimbatore - 641035.</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td style="border-top:1px solid #000000;"> </td>
<td style="border-top:1px solid #000000;"> </td>
<td style="border-top:1px solid #000000;"> </td>
</tr>
<tr>
<th colspan="3" style="text-align:center;">REGISTRATION FORM</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td style="text-align:right;"><label>Reg.No. : <?php if(isset($aid)){echo $aid;}?></label></td>
</tr>
<tr>
<td>1.</td>
<th><label>Name of the child<br/><span style="font-size:16px;">(In Block letter)</span></label></th>
<td><label><?php if(isset($name)){echo $name;}?></label></td>
</tr>
<tr>
<td>2.</td>
<th><label>Sex</label></th>
<td><label><?php if(isset($sex)){echo $sex;}?></label></td>
</tr>
<tr>
<td>3.</td>
<th><label>Name of Parents</label></th>
<td>
<table style="text-align:left;" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>i.</td>
<th><label>Father : </label></th>
<td><label><?php if(isset($father)){echo $father;}?></label></td>
</tr>
<tr>
<td>ii.</td>
<th><label>Mother : </label></th>
<td><label><?php if(isset($mother)){echo $mother;}?></label></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>4.</td>
<th><label>Address for <br/>communication</label></th>
<td><label><?php if(isset($address)){echo $address;}?></label></td>
</tr>
<tr>
<td>5.</td>
<th>Contact No</th>
<td><label><?php if(isset($mobile)){echo $mobile;}?></label></td>
</tr>
<tr>
<td>6.</td>
<th><label>Occupation of <br/>Parents with details</label></th>
<td>
<table style="text-align:left;" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>i.</td>
<th><label>Father : </label></th>
<td><label><?php if(isset($father_occ)){echo $father_occ;}?></label></td>
</tr>
<tr>
<td>ii.</td>
<th><label>Mother : </label></th>
<td><label><?php if(isset($mother_occ)){echo $mother_occ;}?></label></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>7.</td>
<th><label>Date of Birth<br/><span style="font-size:16px;">(as per Birth certificate)</span></label></th>
<td><label><?php if(isset($dob)){echo $dob;}?></label></td>
</tr>
<tr>
<td>8.</td>
<th><label>No of Year & Months that will be<br/>Completed as on June 1st</label></th>
<td><label><?php if(isset($age)){echo $age;}?></label></td>
</tr>
<tr>
<td>9.</td>
<th><label>Religion & Caste<br/><span style="font-size:16px;">for Statistical purpose only</span></label></th>
<td><label><?php if(isset($religion)){echo $religion;}?></label></td>
</tr>
<tr>
<td colspan="3">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>Date : <?php if(isset($cur_date)){echo $cur_date;}?></label></td>
<td style="text-align:right;">Signature of Parent/Guardian</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
window.open does (surprise) open a new browser window. Are you sure there is no pop-up blocker active in your browser? Otherwise you might miss the popup. You can debug Javascript with the F12 debugging tools in all major browsers. Set a breakpoint to the window.open line and see if the line is called. Some pop-up blockers also log to the console also available via F12
window.open() unfortunately has a way of getting 'blocked' by most browsers as an 'unwanted' pop-up if used during a page load - it is probably advisable to use a different way of calling the window.open() statement. An alternative way to accomplish what you are attempting (and side stepping popup blockers) is to consider changing your statement in app_print.php:
echo "<script type='text/javascript'>var url='app_print.php?id=$cur_date&c_name=$name';window.open(url)</script>";
to something like:
echo "<script type='text/javascript'>window.onload=function () { window.location='/app_print.php?id=$cur_date&c_name=$name' }; </script>";
and thus not using window.open() at all.

How to update stock table after making a sale

i'm creating an inventory management system and i can't figure out how to link inventory table with the sales table so that products in inventory table are updated when a sale is made. I'm using MySql
Here's the sold.php, When I sell a product this page save a record in sale table but i want to update manuf table qtyleft row.
<?php require_once('../Connections/bidco.php'); ?>
<?php
mysql_select_db($database_bidco, $bidco);
$query_rsSaletype = "SELECT * FROM saletype ORDER BY type ASC";
$rsSaletype = mysql_query($query_rsSaletype, $bidco) or die(mysql_error());
$row_rsSaletype = mysql_fetch_assoc($rsSaletype);
$totalRows_rsSaletype = mysql_num_rows($rsSaletype);
mysql_select_db($database_bidco, $bidco);
$query_rsCustomercategory = "SELECT * FROM buyertype ORDER BY type ASC";
$rsCustomercategory = mysql_query($query_rsCustomercategory, $bidco) or die(mysql_error());
$row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory);
$totalRows_rsCustomercategory = mysql_num_rows($rsCustomercategory);
mysql_select_db('invmgt', mysql_connect('localhost','root','dream2014')) or die(mysql_error());
?>
<?php
//Start session
session_start();
//Unset the variables stored in session
unset($_SESSION['SESS_ID']);
unset($_SESSION['SESS_Username']);
unset($_SESSION['SESS_Name']);
?>
<?php
if (isset ($_POST ['Submit']))
{
$da=date("Y-m-d");
$itemname=$_POST['itemname'];
$itemcode=$_POST['itemcode'];
$itemtype=$_POST['itemtype'];
$price=$_POST['unitprice'];
$quantity=$_POST['quantity'];
$ttype=$_POST['select2'];
$ccat=$_POST['select'];
$idate=date("Y-m-d");
mysql_query("INSERT INTO sold_goods (itemname, itemcode, itemtype, unitprice, quantity, transactiontype, customercategory, Date) VALUES ('$itemname', '$itemcode', '$itemtype', '$unitprice', '$quantity', '$ttype', '$ccat', '$idate')");
header("location:sold.php");
}
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="711" height="27" border="0">
<tr>
<td width="216">Manufactured Goods </td>
<td width="152">Sold Goods </td>
<td width="148">Client Details </td>
<td width="167">User Accounts </td>
<td width="167">Home </td>
<td width="167"><div align="right">Logout </div></td>
</tr>
</table>
<p> </p>
<form id="form9" name="form9" method="POST" action="">
<table width="828" height="572" border="1" align="center">
<tr>
<td height="55" colspan="3"><div align="center"><strong>SOLD GOODS </strong></div></td>
</tr>
<tr>
<td height="33" colspan="2">User</td>
<td height="33"><?php date_default_timezone_set('Africa/Nairobi'); echo "Time " . date("h:i:sa");
?></td>
</tr>
<tr>
<td height="14">Customer code
<div align="center"></div></td>
<td height="14">Customer category
<select name="select2">
<?php
do {
?>
<option value="<?php echo $row_rsCustomercategory['type']?>"><?php echo $row_rsCustomercategory['type']?></option>
<?php
} while ($row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory));
$rows = mysql_num_rows($rsCustomercategory);
if($rows > 0) {
mysql_data_seek($rsCustomercategory, 0);
$row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory);
}
?>
</select></td>
<td height="14"><?php echo "Date of Transaction " . date("Y/m/d")?></td>
</tr>
<tr>
<td height="15"> </td>
<td height="15"> </td>
<td height="15"> </td>
</tr>
<tr>
<td height="32" colspan="2"><div align="center"><strong>ITEM DETAILS </strong></div></td>
<td width="258" rowspan="3"><div align="center"></div>
<div align="center"></div></td>
</tr>
<tr>
<td width="227" height="23"><div align="right">Item name </div></td>
<td width="321"><input name="itemname" type="text" id=itemname /></td>
</tr>
<tr>
<td><div align="right">Item code </div></td>
<td><input name="itemcode" type="text" id="itemcode" /></td>
</tr>
<tr>
<td><div align="right">Item type </div></td>
<td><input name="itemtype" type="text" id="itemtype" /></td>
<td rowspan="3"><div align="center"></div></td>
</tr>
<tr>
<td height="23"><div align="right">Unit price </div></td>
<td><input name="unitprice" type="text" id=price /></td>
</tr>
<tr>
<td height="32"><div align="right">Quantity </div></td>
<td><input name="quantity" type="text" id=qty /></td>
</tr>
<tr>
<td height="42" colspan="2"><div align="center"><strong>SALES</strong></div></td>
<td><div align="center"></div>
<div align="center"></div></td>
</tr>
<tr>
<td><div align="right">Gross</div></td>
<td> </td>
<td><div align="center"></div></td>
</tr>
<tr>
<td><div align="right">Type of sale </div></td>
<td><select name="select">
<?php
do {
?>
<option value="<?php echo $row_rsSaletype['type']?>"><?php echo $row_rsSaletype['type']?></option>
<?php
} while ($row_rsSaletype = mysql_fetch_assoc($rsSaletype));
$rows = mysql_num_rows($rsSaletype);
if($rows > 0) {
mysql_data_seek($rsSaletype, 0);
$row_rsSaletype = mysql_fetch_assoc($rsSaletype);
}
?>
</select></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="28" colspan="2"><div align="center"><strong>DEDUCTIONS</strong></div></td>
<td> </td>
</tr>
<tr>
<td height="36"><div align="right">Discount</div></td>
<td height="36"> </td>
<td><div align="center">
<input type="submit" name="Submit" value="ADD NEW" />
</div></td>
</tr>
<tr>
<td height="36"><div align="right">V.A.T</div></td>
<td height="36"> </td>
<td> </td>
</tr>
<tr>
<td height="36"><div align="right">Net</div></td>
<td height="36"> </td>
<td rowspan="2"><div align="center">
<input type="reset" name="Submit5" value="CANCEL" />
</div></td>
</tr>
<tr>
<td height="30" colspan="2"><div align="center">
<label><strong>CALCULATE</strong></label>
</div></td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rsSaletype);
mysql_free_result($rsCustomercategory);
?>
This is manuf.php for adding new stock
<?php require_once('../Connections/bidco.php'); ?>
<?php
if (isset ($_POST ['Submit']))
{
$da=date("Y-m-d");
$itemname=$_POST['itemname'];
$itemcode=$_POST['itemcode'];
$itemtype=$_POST['itemtype'];
$unitprice=$_POST['unitprice'];
$quantity=$_POST['quantity'];
$idate=date("Y-m-d");
mysql_query("INSERT INTO manuf (itemname, itemcode, itemtype, price, qtyleft, Date) VALUES ('$itemname', '$itemcode', '$itemtype', '$unitprice', '$quantity', '$idate')");
header("location:manuf.php");
}
?>
?><!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<table width="711" height="27" border="0" align="center">
<tr>
<td width="216">Inventory</td>
<td width="152">Sold Goods </td>
<td width="148">Client Details </td>
<td width="167">User Accounts </td>
<td width="167">Home </td>
</tr>
</table>
<p> </p>
<form id="form1" name="form1" method="POST" action="">
<table width="743" height="282" border="1" align="center">
<tr>
<td colspan="3"><div align="center"><strong>ADD NEW PRODUCT </strong></div></td>
</tr>
<tr>
<td colspan="2">Username </td>
<td width="265"><?php date_default_timezone_set('Africa/Nairobi'); echo "Time " . date("h:i:sa");
?></td>
</tr>
<tr>
<td width="180"><div align="right">Item name </div></td>
<td width="276"><input name="itemname" type="text" id="itemname" /></td>
<td> </td>
</tr>
<tr>
<td><div align="right">Item code </div></td>
<td><input name="itemcode" type="text" id="itemcode" /></td>
<td><div align="center"></div></td>
</tr>
<tr>
<td><div align="right">Type</div></td>
<td><input name="itemtype" type="text" id="itemtype" /></td>
<td><div align="center"></div></td>
</tr>
<tr>
<td><div align="right">Unit price </div></td>
<td><input name="unitprice" type="text" id="unitprice" /></td>
<td><div align="center"></div></td>
</tr>
<tr>
<td><div align="right">Quantity</div></td>
<td><input name="quantity" type="text" id="quantity" /></td>
<td><div align="center">
<input type="submit" name="Submit" value="Add stock" />
</div></td>
</tr>
<tr>
<td><div align="right">Date</div></td>
<td><input name="idate" type="varchar" id="idate" /></td>
<td><div align="center">
<input type="reset" name="Submit5" value="Cancel" />
</div></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<div align="center"></div>
<div align="center"></div>
<p> </p>
</body>
</html>
After inserting to sold table, update the manf table as well:
mysql_query("INSERT INTO sold_goods
(itemname, itemcode, itemtype, unitprice, quantity,
transactiontype, customercategory, Date)
VALUES
('$itemname', '$itemcode', '$itemtype', '$unitprice',
'$quantity', '$ttype', '$ccat', '$idate')");
mysql_query("UPDATE manuf SET qtyleft = qtyleft - $quantity where
itemcode = '$itemcode'" );

how to populate data from a clickable div to a textbox?

I am trying to populate data from a click-able div container to a text box.
All the below code is present in same file "schedule.php".
The jQuery function is:
$(document).ready(function(){
$("#listItem1").click(function(){
var selectedAddress = $("#listItem1").attr("value");
$.post("schedule.php",selectedAddress,function(selectedAddress){
addressSelect($("#listItem1").attr("value"));
});
});
});
The php code is present in the same file:
<?php
function addressSelect($selectedAddress) {
$selectedAddress=$_POST['$selectedAddress'];
//echo $selectedAddress;
if(isset($selectedAddress)) list($fromName, $fromAddress, $fromCity, $fromState, $fCountry, $fromZip, $fromPhone) = explode("$$$", $selectedAddress);
}
?>
I am not able to populate it. I tried to using $.ajax also... but not helping.. what should I do to populate the textboxes at all.
The HTML is like this:
<table CELLSPACING=0 CELLPADDING=1 border=0 width=200>
<tr><td colspan=4 height=10></td></tr>
<tr>
<td width=7></td>
<td WIDTH=180 height=35><b>Name</b><font size="-1" color="#FF0000">*</font></td>
<td colspan=2 WIDTH=220>
<input NAME="fromName" TYPE="text" id="fromName" placeholder="Sender's Name" style="width:150px;" value="<?php echo $fromName;?>" MAXLENGTH="35" autofocus onBlur="ValidateName(fromName)">
<span class="error"> <?php echo $fromNameErr;?></span>
</td>
</tr>
<tr>
<td></td>
<td height=35><b>Address</b><font size="-1" color="#FF0000">*</font></td>
<td>
<TEXTAREA NAME="fromAddress" COLS=30 ROWS=3 id="fromAddress" placeholder="Sender's Address" style="width:200px; height:130px; font-size:13px; font-family:Arial,sans-serif" onBlur="ValidateAddress(fromAddress)"></TEXTAREA>
<span class="error"> <?php echo $fromAddressErr;?></span>
</td>
<td rowspan=3 align="center"></td>
</tr>
<tr>
<td></td>
<td height=35><b>Landmark</td>
<td>
<input NAME="fromLandmark" TYPE="text" id="fromLandmark" placeholder="optional" style="width:150px" value="<?php echo $fromLandmark;?>" MAXLENGTH=45>
</td>
</tr>
<tr>
<td></td>
<td height=35><b>City</b><font size="-1" color="#FF0000">*</font></td>
<td>
<input NAME="fromCity" TYPE="text" id="fromCity" placeholder="Source City" style="width:150px" value="<?php echo $fromCity;?>" MAXLENGTH=35>
</td>
</tr>
<tr>
<td></td>
<td height=35><b>State</b><font size="-1" color="#FF0000">*</font></td>
<td colspan=2>
<input NAME="fromState" TYPE="text" id="fromState" placeholder="State of Source City" style="width:150px" value="<?php echo $fromState;?>" MAXLENGTH=25>
</td>
</tr>
<tr>
<td></td>
<td height=35><b>Zip</b><font size="-1" color="#FF0000">*</font></td>
<td colspan=2>
<input NAME="fromZip" TYPE="text" id="fromZip" placeholder="Pin Code" style="width:90px" value="<?php echo $fromZip;?>" MAXLENGTH=15 onBlur="ValidateZip(fromZip)">
<span class="error"> <?php echo $fromZipErr;?></span>
</td>
</tr>
<tr>
<td></td>
<td height=35><b>Country</b></td>
<td colspan=2>
<select NAME="fromCountry" id="fromCountry" disabled="disabled">
<?php populate_country();?>
</select></div></td>
</td>
</tr>
<tr>
<td></td>
<td height=35><b>Phone</b><font size="-1" color="#FF0000">*</font></td>
<td colspan=2>
<input NAME="fromPhone" TYPE="text" id="fromPhone" placeholder="Sender's Phone no." style="width:150px" value="<?php echo $fromPhone;?>" MAXLENGTH=15 onBlur="ValidatePhone(fromPhone)">
<span class="error"> <?php echo $fromPhoneErr;?></span>
</td>
</tr>
<tr><td colspan=4 height=10></td></tr>
</table>
<?php /*?><td style="border-right:1px solid #b2b2b2; font-size:1px; background-color: #fafafa"> </td><?php */?>
</tr>
<tr>
<td width=6 height=6></td>
<?php /*?><td height=6 style="border-bottom:1px solid #b2b2b2; font-size:1px; background-color: #fafafa"> </td><?php */?>
<td width=6 height=6></td>
</tr>
</table><!-- End of From Address container table-->
The code provided by #user2298875 has a little mistake. Change
content = $("#" + divId).innerHTML;
$("#" + textBoxId).value = content;
to
$("#" + textBoxId).val($("#" + divId).html());
I think you want to copy the data on the browser and not on the server. You can use the following JQuery code to get it done:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script language="javascript" type="text/javascript">
function copyData(divId, textBoxId) {
content = $("#" + divId).html();
$("#" + textBoxId).val(content);
}
</script>
<body>
<div id="my-div" onclick="copyData('my-div', 'my-text-box');">
This the data to be copied.
</div>
<input type="text" id="my-text-box" name="myTextBox"/>
</body>

populate triple drop down in ajax and php in a form

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>

Jquery Onclick doesnt seem to work for me

My php page uses sequence of three radio buttons and two out of three calls jquery click event and toggles a div accordingly...
Here is my Jquery function....
$(function() {
$("#click_here").click(function(event) {
event.preventDefault();
$("#div1").slideToggle();
});
$("#div1 a").click(function(event) {
event.preventDefault();
$("#div1").slideUp();
});
});
$(function() {
$("#click").click(function(event) {
event.preventDefault();
$("#div2").slideToggle();
});
$("#div2 a").click(function(event) {
event.preventDefault();
$("#div2").slideUp();
});
});
and my radio buttons are
<input type="radio" name="Modeofpayment" value="1">Cash
<div>
<div id="id" style="width:411x; height:20px;">
<input type="radio" name="Modeofpayment" id="click_here" value="2">DD
</div>
<div style="display: none;" id="div1">
<div style="float:right;">
[x]
</div>
<input type="hidden" name="chkVal" id="chkVal" size="20">
<table border="0" width="200" align="center">
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>College Bank Name</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtCollegeBankName' id='txtCollegeBankName'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>DD NO</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtDDNO' id='txtDDNO'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>DD Amount</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtDDAMT' id='txtDDAMT'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>DD Bank Name</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtBankName' id='txtBankName'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>Remarks</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtRemarks' id='txtRemarks'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
</table>
</div>
<div>
<div id="id" style="width:411x; height:20px;">
<input type="radio" name="Modeofpayment" id="click" value="3">Cheque
</div>
<div style="display: none;" id="div2">
<div style="float:right;">
[x]
</div>
<input type="hidden" name="chkVal" id="chkVal" size="20">
<table border="0" width="200" align="center">
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>College Bank Name</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtCollegeBankName' id='txtCollegeBankName'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>CHQ NO</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtDDNO' id='txtDDNO'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>CHQ Amount</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtDDAMT' id='txtDDAMT'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>CHQ Bank Name</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtBankName' id='txtBankName'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
<tr>
<td style="width:5px"> </td>
<td class="table_label" width='100px'>Remarks</td>
<td style="width:10px"> </td>
<td>
<input type='text' name='txtRemarks' id='txtRemarks'
Class='text_box_height_14_width_150' >
</td>
<td></td>
<td style="width:5px"> </td>
</tr>
</table>
</div>
By default i can select one but i cant select another one ... My previous radio button remains selected and my new radio button click toggles the div but its not selected....
Your radio buttons are not selected because you have event.preventDefault(); on your click functions - this cancels the click and doesn't select them.
Simply remove these lines.
Right from the very beginning of your markup, you don't close your <input> tag.
In fact, you never close any of your input tags.

Categories