Create barcode reader using AJAX in PHP - php

I'm trying to build an application using php. in "stock_out.php", i wanna create a form that include two barcodes. I have 8 fields. (1)Effectivedate,(2)Partnumber,(3)Description1,(4)Description2,(5)NPK,(6)Nama,(7)QtyOut,(8)Reason. I wanna using barcode-reader in "Partnumber" and "NPK".
I have some problems:
1. When i press enter, it's respon for button submit.
2. Actually, when i press enter in Partnumber, i want show details data in "description1" and "description2". As well as in NPK, i want show details data in "nama"
3. In the end of form, i still want to submit this form into database.
I'm newbie in AJAX, so i still don't know how to implementation AJAX in PHP. This is my code, I am grateful for the help
<html><body>
<div id="outerContainer">
<?php include("headerFile.html"); ?>
<?php include("navigationFile.html"); ?>
<div id="bodyContainer">
<div id="pageBodyTitle"> Stock Out </div> <br>
<form id="formSearch" name="formSearch" method="post" action="proses_out.php" onSubmit="return cek_data();">
<table id="messageTable">
<tr>
<td class="heading"> Effective Date </td>
<td>
<input class="inputField" name="tgl" type="text" readonly value="<?php echo $_POST['tgl']?>" tabindex="1"/>
<script language='JavaScript'>new tcal ({'formname': 'formSearch','controlname': 'tgl'});</script>
</td>
</tr>
<tr>
<td class="heading"> Part Number </td>
<td><input type='text' name='txtItem' id='txtItem' size="20" class="inputField" value='<?php echo $item;?>' tabindex="2" />
<img src='search.ico' onClick='open_win_item()'> </td>
</tr>
<tr>
<td class="heading">Description1</td>
<td><input type='text' name='txtDesc1' id='txtDesc1' size="50" value='<?php echo $desc1;?>' readonly /></td>
</tr>
<tr>
<td class="heading">Description2</td>
<td><input type='text' name='txtDesc2' id='txtDesc2' size="50" value='<?php echo $desc2;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> NPK </td>
<td><input type='text' name='txtNpk' id='txtNpk' size="20" maxlength="5" class="inputField" value='<?php echo $tr_no;?>' tabindex="3" />
<img src='search.ico' onClick='open_win_npk()'></td>
</tr>
<tr>
<td class="heading">Nama</td>
<td><input type='text' name='txtName' id='txtName' size="30" value='<?php echo $nama;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> Qty Out </td>
<td><input type='text' name='txtQty' id='txtQty' size="5" class="inputField" tabindex="4"/></td>
</tr>
<tr>
<td class="heading"> Reason </td>
<td><select class="inputField" name="choose" id="choose" value="" tabindex="5">
<?php
include "/class/connect_SQL.class.php";
$sql = "select reason_code from Inv_reason_master";
$query = mssql_query($sql);
while ($row = mssql_fetch_array($query))
{
$coba = $row['reason_code'];
?>
<option value="<?php echo $coba; ?>"><?php echo $coba;?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submit" value="Save" class="formButton2" tabindex="6"/>
<input type="reset" name="reset" value="Cancel" class="formButton2" tabindex="7"/>
</td>
</tr>
</table>
</form>
</div>
<?php
if(isset($_GET["message"]) and $_GET["message"]='save')
{
echo "<script language=\"javascript\"> alert('Data Tersimpan!') </script>";
}
?>
<?php include("footerFile.html"); ?>
</div>

You will have to prevent the response of the "Enter"-key. If you are using jquery in your project you can prevent it with this code:
$(function() {
$("form").bind("keypress", function(e) {
if (e.keyCode == 13) return false;
});
});
To bind Enter key to "Part number" field instead you could try this:
$('#txtItem').keypress(function(e) {
if (e.keyCode == 13) {
alert('Enter is pressed in part number');
}
});

Related

I write code simple update and its run but name field value not proper fetch in input box, it is only fetch before white space string

<?php
include ('bcpdb.php');
if (isset($_POST['ok']));
$ern=$_POST['erno'];
$cname=$_POST['name'];
$cb=$_POST['branch'];
$cay=$_POST['admyear'];
$iq= "UPDATE stuinfo SET ERNO=$ern, SNAME='$cname',BRANCH='$cb',ADMYEAR='$cay' WHERE ERNO=$ern";
$query=mysqli_query($con,$iq);
mysqli_close($con);
echo '<script> window.location="stulist.php"</script>';
<! DOCTYPE html>
<html>
<head><title>Update</title>
<script type="text/javascript" src="vForm.js"></script>
</head>
<body>
<?php
include 'menu.php'; ?>
<?php
include 'bcpdb.php';
$erno=$_GET['erpass'];
$nm=$_GET['npass'];
$br=$_GET['bpass'];
$ay=$_GET['ypass'];
?>
<form name="f1" method="post" action="updatestu.php" onsubmit="return vForm()" >
<table border=0>
<tr><td colspan=2 ><center><h3>UPDATE STUDENT PROFILE</h3></center></td></tr>
<tr>
<td><label for="fname">Enrollnment No</label></td>
<td><input type="text" name="erno" value=<?php echo "$erno"; ?> ></td>
</tr>
<tr>
<td><label for="fname">Name</label></td>
<td><input type="text" name="name" value=<?php echo "$nm"; ?> ></td>
<tr>
<td><label for="fname">Branch</label></td>
<td><input type="text" name="branch" value=<?php echo "$br"; ?> ></td>
</select></td>
</tr>
<tr>
<td><label for="fname">Addmision Year</label></td>
<td><input type="text" name="admyear" value=<?php echo "$ay"; ?> ></td>
</tr>
<td colspan=2 align=center>
<button type="submit" name="ok">SUBMIT </button></td>
</table>
</form>
</body>
</html>
?>enter image description here
You are using wrong PHP tag.
<td><input type="text" name="admyear" value=<?php echo "$ay"; ?> ></td>
It should be:
<td><input type="text" name="admyear" value="<?php echo $ay; ?>" ></td>

update in php not working

i update php form and change the value but it cant change it saves the same previous value
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id="total_fees">
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
</tr>
Please see the screenshot of source code and input filed . i changed the value in input field but it remain same in source code and save source code value db
The input values not immediately affect on your input but You will get your new value while you submitting your form.
So submit your form and then print the values of the Request. You will find the new value of total_fees into the request parameters.
HTML CODE
<form name="jqueryForm" method="post" id="jqueryForm" enctype="multipart/form-data" onSubmit="return validme();">
<table border="0" cellspacing="15" cellpadding="0" width="100%" >
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id=total_fees>
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
<td width="40%"></td>
</tr>
<tr>
<td width="22%">Discount in <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo percent; ?>" checked="checked" onChange="show_record()" />% or <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo cash; ?>" onChange="show_record()" />Cash</td>
<td width="38%"><input type="text" class="input_text" name="concession" id="concession" value="<?php if($_POST['concession']) echo $_POST['concession']; else if($row_record['discount'] !=0) echo $row_record['discount']; else echo 0; ?>" onBlur="show_record()"/>
</td>
<td width="40%"></td>
</tr>
</table>
<input type="submit" value="Save Record" name="save_changes" />
</form>
PHP CODE FOR SAVE IN DB
if(isset($_POST['save_changes']))
{
$total_fees=($_POST['total_fees']) ? $_POST['total_fees'] : "0";
$data_record['total_fees']=$total_fees;
$courses_id=$db->query_insert("enroll", $data_record);
}

I need the (Submit this form )button to be clicked automatically when the page loads (WORDPRESS)

iam customizing a page in wordpress , i dont need the user to see this page when it loads , so i need the Sumnit this form button to be clicked automatically the moment this page loads-for security reasons-...the user doesnt need to fill anything on this form.
this is the button code:
<td colspan="2" align="center"><input name="submitBtn" type="submit"value="Submit This Form" /></td>
and this is the complete code:
[insert_php]
date_default_timezone_set('Asia/Kolkata');
$dateTime= date('Y:m:d-H:i:s');
function getDateTime() {
global $dateTime;
return $dateTime;
}
function createHash($chargetotal,$Currency) {
$storeId = "330995001";
$sharedSecret = "sharedsecret";
$dateTime= date('Y:m:d-H:i:s');
$stringToHash = $storeId . $dateTime . $chargetotal . $Currency .
$sharedSecret;
$ascii = bin2hex($stringToHash);
return sha1($ascii);
}
[/insert_php]
IPG Connect Sample for PHP(hashing)
<h1>Order Form</h1>
[insert_php]
$responseSuccessURL = "http://127.0.0.1:8006/wordpress/?page_id=27";
$responseFailURL = "http://127.0.0.1:8006/wordpress/?page_id=31";
[/insert_php]
<form action="https://test.ipg-online.com/connect/gateway/processing"
method="post"><input name="timezone" type="hidden" value="IST" />
<input name="authenticateTransaction" type="hidden" value="true" />
<table>
<tbody>
<tr>
<td>Transaction Type</td>
<td><input name="txntype" size="50" type="text" value="sale" /></td>
</tr>
<tr>
<td>Transaction Date Time</td>
<td><input name="txndatetime" size="50" type="text" value="[insert_php] echo
$dateTime; [/insert_php]" /></td>
</tr>
<tr>
<td>Calculated HASH</td>
<td><input name="hash" size="50" type="text" value="[insert_php] echo
createHash("1","356"); [/insert_php]" /></td>
</tr>
<tr>
<td>Currency</td>
<td><input name="currency" size="50" type="text" value="356" /></td>
</tr>
<tr>
<td>Payment Mode</td>
<td><input name="mode" size="50" type="text" value="payonly" /></td>
</tr>
<tr>
<td>Store Id</td>
<td><input name="storename" size="50" type="text" value="330995001" /></td>
</tr>
<tr>
<td>Chargetotal</td>
<td><input name="chargetotal" size="50" type="text" value="1" /></td>
</tr>
<tr>
<td>Shared Secret</td>
<td><input name="sharedsecret" size="50" type="text" value="sharedsecret" />
</td>
</tr>
<tr>
<td>Language</td>
<td><select name="language">
<option value="de_DE">Deutsch</option>
<option selected="selected" value="en_EN">English</option>
</select></td>
</tr>
<input type="hidden" name="responseSuccessURL" value="[insert_php] echo
$responseSuccessURL; [/insert_php]"/>
<input type="hidden" name="responseFailURL" value="[insert_php] echo
$responseFailURL; [/insert_php]"/>
<tr>
<td colspan="2" align="center"><input name="submitBtn" type="submit"
value="Submit This Form" /></td>
</tr>
<input type="hidden" name="hash_algorithm" value="SHA1"/>
</tbody>
</table>
</form>
[/insert_php]
with Javascript, you can do it like
window.onload = function() {
document.getElementById("formId").submit();
};
You can do it with JQuery like this:
<script type="text/javascript">
$(document).ready(function(){
$( "#formId" ).submit(
});
</script>
I am submitting form directly, you can click on submit button as well that will do that submit operation.
You can use trigger after document is ready,
<script type="text/javascript">
$(document).ready(function(){
$( "#foo" ).trigger( "click" );
});
</script>
Just replace the foo with your submit button ID

How to create a jquery function to prevent duplicate entries to the database

I have created a form which takes the data and inserts it in the database. onlick of create button i want the function to check database whether the entry with employee_id already exists. if exists i want it to display the data already exists do you still want to insert, i am noob in this can anybody help me with this. the form is
<form id="myForm" name="myForm" action='insert.php' method='post' >
<input type='hidden' name='st' value=0>
<table style="text-align:center; width:100%">
<tr>
<td style="text-align:right"><label>Select SE/AE:</label></td>
<td style="text-align:left">
<?php include("configs.php");
$sql = "SELECT DISTINCT seae FROM se_ae ";?>
<select name="seae">
<option value="" selected></option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['seae']; ?>">
<?php echo $row['seae']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label>Select Brand:</label></td>
<td style="text-align:left">
<?php //include("configs.php");
$sql = "SELECT DISTINCT `brand` FROM se_ae ";?>
<select name="brand">
<option value="" selected> </option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['brand']; ?>">
<?php echo $row['brand']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label>Select Territory:</label></td>
<td style="text-align:left">
<?php //include("configs.php");
$sql = "SELECT DISTINCT `territory` FROM se_ae ";?>
<select name="territory">
<option value="" selected></option>
<?php foreach ($dbo->query($sql) as $row) { ?>
<option value="<?php echo $row['territory']; ?>">
<?php echo $row['territory']; ?></option>
<?php }?>
</select>
</td>
</tr>
<tr>
<td style="text-align:right"><label for="name">Employee Name:</label></td>
<td style="text-align:left">
<input type="text" id="name" name="name"/>
</td>
</tr>
<tr>
<td style="text-align:right"><label for="number">Employee ID:</label></td>
<td style="text-align:left">
<input type="text" id="number" name="number" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="email"> Email:</label></td>
<td style="text-align:left">
<input type="text" id="email" name="email" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="contact"> Contact:</label></td>
<td style="text-align:left">
<input type="text" id="contact" name="contact" />
</td>
</tr>
<tr>
<td style="text-align:right"><label for="exist"> Exist:</label></td>
<td style="text-align:left">
<input type="radio" id="exist" name="exist" value="Active"/>Active
<input type="radio" id="exist" name="exist" value="NA"/>NA
</td>
</tr>
<tr>
<td style="text-align:right" class='swMntTopMenu'>
<input style="background-color:rgb(255,213,32)" name="Reset" type="reset" value="Reset">
</td>
<td style="text-align:left" class='swMntTopMenu'>
<input style="background-color:rgb(255,213,32)" name="submit" type="submit" value="Create">
</td>
</tr>
</table>
</form>
You can use the Jquery validation
$(function () {
$("#resturantRegistration").validate({
rules: {
number: {
required: true,
remote:"user/checkEmployee"
}
},
messages: {
number: {
required: "Please enter Employee id",
remote: $.validator.format("Employee id already in use")
}
}
});
});
PHP function
function checkEmployee(){
$emailid = $_GET['number'];
if(!empty($emailid)){
$emailRes = $this->users->is_email_available($emailid);
if ($emailRes == ''){
echo 'false';
} else {
echo 'true';
}
}
}
Model function to check with database
/**
* Check if email available for registering
*
* #param string
* #return bool
*/
function is_email_available($email)
{
$this->db->select('1', FALSE);
$this->db->where('LOWER(email)=', strtolower($email));
$this->db->or_where('LOWER(new_email)=', strtolower($email));
$query = $this->db->get($this->table_name);
return $query->num_rows() == 0;
}
above code is follow the codeigniter MVC framework you can customize this in core PHP as well

table cuts off page after 2nd <td>

I don't know why but my table cuts off right after the second <td> tag... can anyone help, I have constantly looked over it over and over. Can someone help me find where the problem is?
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("newpass")); ?>
</td>
</tr>
Btw, that code is only the first two rows.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<form action="adminprocess.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?php
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?php
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("newpass")); ?>
</td>
</tr>
<tr>
<td>Confirm New Password:</td>
<td><input name="conf_newpass" type="password" value='
<?php echo $form->value("newpass"); ?>' size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
</tr>
<td>Edit motto:</td>
<td><input type="text" size="56" name="motto" value='<?php
if($form->value("motto") == ""){
echo $req_user_info['motto'];
}else{
echo $form->value("motto");
}
?>'></td>
<tr>
<tr>
<td>Edit profile bio:</td>
<td><textarea cols="40" rows="10" name="profile" value=""><?php
if($form->value("profile") == ""){
echo $req_user_info['profile'];
}else{
echo $form->value("profile");
}
?></textarea></td>
<tr>
<tr>
<td>Email:</td>
<td><input name="email" type="text" value='
<?php
if($form->value("email") == ""){
echo $req_user_info["email"];
}else{
echo $form->value("email");
}
?>' size="56" maxlength="50">
</td>
<td><?php echo $form->error("email"); ?></td>
</tr>
<tr>
<td>User level:</td>
<td><input name="userlevel" type="text" value='
<?php
if($form->value("userlevel") == ""){
echo $req_user_info["userlevel"];
}else{
echo $form->value("userlevel");
}
?>' size="4" maxlength="10"></td>
<td><?php echo $form->error("userlevel"); ?></td>
</tr>
<tr><td align="right">
<input type="hidden" name="subedit" value="1">
<input type="hidden" name="usertoedit" value="<?php echo $usertoedit; ?>">
<input type="submit" name="button" value="Edit Account">
</td>
<td colspan="2" style="text-align:right;">
<input type="submit" name="button" value="Delete" onclick="return confirm ('Are you sure you want to delete this user, this cannot be undone?\n\n' + 'Click OK to continue or Cancel to Abort!')">
</td>
</tr>
</table>
</form>
I've changed your syntax a little..
<tr>
<td>Username:</td>
<td><input name="username" type="text" value="<?php echo htmlspecialchars(($form->value("username")=="" ? $req_user_info["username"] : $form->value("username"))); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("username"); ?></td>
</tr>
<tr>
<td>New Password:</td>
<td><input name="newpass" type="password" value="<?php echo htmlspecialchars($form->value("newpass")); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
For additional php error logging, put this at the top of the page:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>

Categories