insert data to database give error result after re edit - php

i found the insert to database code on internet, use it for trying and its works. but, after i add on some more column, i got error on inserting data to database. which i'm using this code
error_reporting(E_ALL);
ini_set('display_errors','on');
to determine error location, but its show no error on coding. only goes to error result. could anyone help me looking for my mistake and my code error?
here is my insert2_db.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">function checkinput() {
var id_mesin = document.getElementById('id_mesin').value;
if(!id_mesin.match(/\S/)) {
alert ('Please enter Machine ID');
return false;
} else {
return true;
}
}
</script>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form_insert" method="post" action="insert_ac.php" onSubmit="return checkinput(this)">
<table width="100%" height="398" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="9"><strong>Insert Data Into EXA_mySQL Database </strong></td>
</tr>
<tr>
<td width="106">MACHINE ID</td>
<td width="6">:</td>
<td colspan="3"><input name="id_mesin" type="text" id="id_mesin"></td>
<td colspan="2">BRAND</td>
<td width="9">:</td>
<td width="164"><select name="jenama">
<option selected>Please select :</option>
<option value="SHARP">SHARP</option>
<option value="TOSHIBA">TOSHIBA</option>
<option value="CANON">CANON</option>
<option value="SAMSUNG">SAMSUNG</option>
<option value="MEXTEC">MEXTEC</option>
</select></td>
</tr>
<tr>
<td>MODEL</td>
<td>:</td>
<td colspan="3"><input name="model" type="text" id="model"></td>
<td colspan="2">METER START</td>
<td>:</td>
<td><input name="meter_awal" type="text" id="meter_awal" value="0"></td>
</tr>
<tr>
<td>SERIAL NO</td>
<td>:</td>
<td colspan="3">MACHINE</td>
<td colspan="2">FEEDER</td>
<td> </td>
<td>FINISHER</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><input name="siri_mesin" type="text" id="siri_mesin"></td>
<td colspan="3"><input name="siri_feeder" type="text" id="siri_feeder"></td>
<td><input name="siri_finisher" type="text" id="siri_finisher"></td>
</tr>
<tr>
<td>STOCK IN</td>
<td>:</td>
<td width="58">DATE</td>
<td width="8">:</td>
<td width="220"><input type="text" name="stok_in" id="stok_in"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="in_do" id="in_do"></td>
</tr>
<tr>
<td>LOCATION</td>
<td>:</td>
<td colspan="3"><select name="lokasi">
<option selected>Please select :</option>
<option value="HQ WAREHOUSE">HQ WAREHOUSE</option>
<option value="CHENDERING WAREHOUSE">CHENDERING WAREHOUSE</option>
</select></td>
<td colspan="2">J.S.O</td>
<td>:</td>
<td><input type="text" name="js_order" id="js_order"></td>
</tr>
<tr>
<td>STOCK OUT</td>
<td>:</td>
<td>DATE</td>
<td>:</td>
<td><input type="text" name="stok_out" id="stok_out"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="out_do" id="out_do"></td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td colspan="7"><input name="pelangan" type="text" id="pelangan" size="90"></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:</td>
<td colspan="7"><textarea name="pelangan_alamat" cols="69" id="pelangan_alamat"></textarea></td>
</tr>
<tr>
<td>CONTACT PERSON</td>
<td>:</td>
<td colspan="4"><input name="pelangan_person" type="text" id="pelangan_person" size="50"></td>
<td width="109">NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="pelangan_no" id="pelangan_no"></td>
</tr>
<tr>
<td>TECHNICIAN INCHARGE</td>
<td>:</td>
<td colspan="4"><input name="tech" type="text" id="tech" size="50"></td>
<td>NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="tech_no" id="tech_no"></td>
</tr>
<tr>
<td>STATUS</td>
<td>:</td>
<td colspan="3"><select name="status">
<option selected>Please select :</option>
<option value="ORDER PURCHASE">ORDER PURCHASE</option>
<option value="RENTAL">RENTAL</option>
<option value="HIRE PURCHASE">HIRE PURCHASE</option>
</select></td>
<td colspan="3"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
<td colspan="3"><input type="reset" value="Clean" /></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
and my insert_ac.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<script type="text/javascript">
<!--
function CloseWindow() {
window.close();
window.opener.location.reload();
}
//-->
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
$con=mysqli_connect("localhost","root","admin","exa");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_mesin=$_POST['id_mesin'];
$jenama=$_POST['jenama'];
$model=$_POST['model'];
$siri_mesin=$_POST['siri_mesin'];
$siri_feeder=$_POST['siri_feeder'];
$siri_finisher=$_POST['siri_finisher'];
$meter_awal=$_POST['meter_awal'];
$lokasi=$_POST['lokasi'];
$status=$_POST['status'];
$pelangan=$_POST['pelangan'];
//$rekod=$_POST['rekod'];
$stok_in=$_POST['stok_in'];
$stok_out=$_POST['stok_out'];
$in_do=$_POST['in_do'];
$out_do=$_POST['out_do'];
$pelangan_alamat=$_POST['pelangan_alamat'];
$pelangan_no=$_POST['pelangan_no'];
$pelangan_person=$_POST['pelangan_person'];
$js_order=$_POST['js_order'];
$tech=$_POST['tech'];
$tech_no=$_POST['tech_no'];
//$sql2="SELECT * FROM aset where id_mesin = '".$id_mesin."'";
//$result2=mysqli_query($con, $sql2);
$sql="INSERT INTO aset(id_mesin, jenama, model, siri_mesin, siri_feeder, siri_finisher, meter_awal, lokasi, status, pelangan, stok_in, stok_out, in_do, out_do, pelangan_alamat, pelangan_no, pelangan_person, js_order, tech, tech_no) VALUES('$id_mesin', '$jenama', '$model', '$siri_mesin', $siri_feeder, $siri_finisher, '$meter_awal', '$lokasi', '$status', '$pelangan', '$stok_in', '$stok_out', '$in_do', $out_do, $pelangan_alamat, '$pelangan_no', '$pelangan_person', '$js_order', '$tech', '$tech_no')";
$result=mysqli_query($con, $sql);
if($result){//if ($result2 !== 1){
echo "Successful";
echo "<BR>";
echo "<th><form>";
echo "<input type='button' onClick='CloseWindow()' value='Back to Exa_mySQL'>";
echo "</form></th>}";
}//}
else {
echo "Data error, please check your submit.";
echo "<BR>";
echo "<a href='insert.php'>Back to insert form</a>";
}
mysqli_close($con);
?>
</body>
</html>
i'm also using some dropdown list as input on my form, which initial value = Please select: and it has null value. i cant insert data even i put all information on my insert form, all goes to this error result.
echo "Data error, please check your submit.";

Related

PHP function not returning values for dynamic drop down

I am facing issue in my dynamic drop down function it not return values i am unable to find where i'm doing wrong.One more issue i am facing regarding this code is that it not open drop down according to menus i.e if i select USA as a country it not show related cities of USA it always show all cities of all countries please set my code i will be highly thankful to you.
function listcatagoery()
{
$query="select * from tblcountry";
$rs=mysqli_query($query);
$html ='<select name="listcatagoery" id="listcatagoery" onchange="submitme();">';
while($row = mysqli_fetch_array($rs))
{
if($cntid == $row['cnt_id'])
{
$html.='<option selected="selected"
value="'.$row['cnt_id'].'">'.$row['cnt_name'].'</option>';
}
else
{
$html.='<option
value="'.$row['cnt_id'].'">'.$row['cnt_name'].'</option>';
}
}
$html.='</select>';
return $html;
}
///////////////////// List sub-catagoery////////
function listsubcatagoery()
{
$query = "select * from tblcity";
$rs=mysqli_query($query);
$html='<select name="listsubcatagoery" id="listsubcatagoery">';
while($row = mysqli_fetch_array($rs))
{
$html.='<option value="'.$row['cit_id'].'">
'.$row['cit_name'].'</option>';
}
$html.='</select>';
return $html;
}
<div id="main">
<div id="right">
<h2>User Registration Here...</h2><br />
<form name="frmadd" id="frmadd" action="" method="post" enctype="multipart/form-data">
<table border="1" cellpadding="5" cellspacing="4" width="90%" align="center">
<tr>
<td>Full Name</td>
<td><input type=text name="textname" size="40" id="textname" required="required"></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="rdgender" value="male" size="10">Male
<input type="radio" name="rdgender" value="Female" size="10">Female</td>
</tr>
<tr>
<td>Email</td>
<td><input type=text name="textemail" size="40" id="textemail" required="required"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="textpass" size="40" id="textpass" required="required"><span class="first"></span></td>
</tr>
<tr>
<td>Country</td>
<td>
<?php echo $htmlcountry; ?>
</td>
</tr>
<tr>
<td>City</td>
<td>
<?php echo $htmlcity; ?>
</td>
</tr>
<tr>
<td>Telephone</td>
<td><input type="number" name="txttel" size="11" id="txttel" required="required"></td>
</tr>
<tr>
<td>Photo</td>
<td><input type="file" name="txtphoto" size="40" id="txtphoto"></td>
</tr>
<tr>
<td>Signin</td>
<td colspan="2" align="center"><input type="submit" name="btnadd" id="btnadd" value="SigIn Now" /></td>
</tr>
<tr>
<td align="center" colspan="2">
<?php echo $msg; ?>
</td>
</tr>
</table>
</form><br />
</div>

Php advance form

I am working on CMS project and dealing with form which is adding information into mysql. Everything is working fine but the "textarea" seems like too simple even with tinymce. I am looking for any advice that help to improve the "texarea" such as add multiple images ( mine is only allowed one).
Thanks you and please abandon my bad English
Here is my code:
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
<form method="post" action="insert_post.php" enctype="multipart/form-data">
<table width="800" align="center" border="10">
<tr>
<td align="center" bgcolor="yellow" colspan="6"><h1>Insert New Post Here</h1></td>
</tr>
<tr>
<td align="right">Post Title:</td>
<td><input type="text" name="post_title" size="30"></td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Category:</strong></td>
<td>
<select name="cat">
<option>Select a Category</option>
<?php
include("includes/connect.php");
$get_cats = "select * from catelogries";
$run_cats = mysql_query($get_cats);
while ($cats_row=mysql_fetch_array($run_cats)){
$cat_id=$cats_row['cat_id'];
$cat_title=$cats_row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right">Post Author:</td>
<td><input type="text" name="post_author" size="30"></td>
</tr>
<tr>
<td align="right">Post Keywords:</td>
<td><input type="text" name="post_keywords" size="30"></td>
</tr>
<tr>
<td align="right">Post Image:</td>
<td><input type="file" name="post_image"></td>
</tr>
<tr>
<td align="right">Post Content:</td>
<td><textarea name="post_content" cols="30" rows="15"></textarea></td>
</tr>
<tr>
<td align="center" colspan="6"><input type="submit" name="submit" value="Publish Now"></td>
</tr>
</table>
<?php
if(isset($_POST['submit'])){
$post_title = $_POST['post_title'];
$post_date = date('m-d-y');
$post_cat = $_POST['cat'];
$post_author = $_POST['post_author'];
$post_keywords = $_POST['post_keywords'];
$post_content = $_POST['post_content'];
$post_image= $_FILES['post_image']['name'];
$post_image_tmp= $_FILES['post_image']['tmp_name'];
if( $post_title=='' or $post_cat=='null' or
$post_author=='' or $post_keywords=='' or
$post_content=='' or $post_image=='')
{
echo "<script>alert('Any of the fields is empty')</script>";
exit();
} else {
move_uploaded_file($post_image_tmp,"../images/$post_image");
$insert_posts = "insert into posts
(category_id,post_title,post_date,
post_author,post_image,post_keywords,
post_content)
values ('$post_cat','$post_title','$post_date',
'$post_author','$post_image','$post_keywords',
'$post_content')";
mysql_query($insert_posts);
echo "<script>alert('post published successfuly')</script>";
exit();
}
}
?>

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'" );

php - drop down from database

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

Categories