This is my view page code:
when i enter the order no some details is fetched from the table.
This second pic shows that it fetched the data and displayed in the view page:
i have used the ajax code to fetch the data.
Now what i have want is if enter the order no is 1 and save into the another table.
now again same page refresh the content if again enter the order no as 1 it should not be displayed in the view page and alert the msg in ajax .
My controller code:
public function DC_Entry_Insert(){
$this->load->model('User_model');
$result = $this->User_model->DC_insert($_POST);
}
My ajax code:
script type="text/javascript">
$(document).ready(function(){
$('#orderno').on('input change',function(){
var orderno = $("#orderno").val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>Inventory/Orderfetch",
data: {
orderno:orderno
},
datatype: 'json',
success: function (data) {
$('#Product_Name_div').html(data);
}
});
});
});
</script>
my model code:
function fetch_item($orderno){
$this->db->where("orderno",$orderno);
$this->db->select('*');
$this->db->join('item_master', 'item_master.id = order_item.itname', 'left');
$this->db->from('order_item');
$query_result = $this->db->get()->result();
$output = '<center><table class="table table-bordered table-striped table-xxs" id="tb2">
<tbody>';
if($query_result !='false'){
$i=0;
foreach ($query_result as $key => $value) {
$output .='<tr>
<td><span class="glyphicon glyphicon-remove" id="remove"></span></td>
<td><input style="width:50px" name="sno[]" type="text" class="form-control input-xs" value="'.$value->sno.'" ></td>
<td><input style="width:250px" name="itemname[]" type="text" class="form-control input-xs" value="'.$value->itemname.'" ></td>
<td><input style="width:80px" name="qty[]" type="text" class="form-control input-xs qty" value="'.$value->qty.'" id="qty_'.$i.'" onchange="calculate('.$i.')"></td>
<td><input style="width:90px" name="wgt[]" type="text" class="form-control input-xs" > </td>
<td><input style="width:150px" name="desc[]" type="text" class="form-control input-xs" > </td>
<td><a href="javascript:void(0);" style="font-size:18px;" class="addMore" title="Add More Person"><span class="glyphicon glyphicon-plus"></td>
</tr>';
$i++;
}
$output .="</tbody>
</table></center>";
echo $output;
}
}
You can do validation before posting to server using javascript or you can do server side. A small example if your are sending data
data: {
orderno:orderno
}
Then you can check on your backend
if($this->input->post('orderno')=='10){
$flag='1';
}else{
$flag='1';
}
return $flag;
then you can show it on html tag or you can show on javascript alert.
Related
My problem is the fetching is correctly works on first row
<script type="text/javascript">
$(document).ready(function () {
$("#tb3").on('input change', function () {
$('#tb3 > tbody > tr').each(function () {
var code = $(this).find('#Product_Code').val();
//var data = $("#tb3 tr:eq(1)").clone(true).appendTo("#tb3");
//var code = data.find("Product_Code").val('');
$.ajax({
type: "POST",
url: "<?php echo base_url();?>TipUp_Loan/fetch",
data: {
code: code
},
datatype: 'json',
success: function (data) {
var json = data,
obj = JSON.parse(json);
$("#Product_Name").val(obj.itemname);
$("#Rate").val(obj.salrate);
//alert(obj);
}
});
});
});
});
</script>
table code:
<table>
<thead>
<tr>
<th></th>
<th>Product Code</th>
<th>Product Name</th>
<th>Qty</th>
<th>Rate</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr >
<td><a href='javascript:void(0);' class='remove3'><span class='glyphicon glyphicon-remove'></span></a></td>
<td>
<input style="width:80px" type="text" id="Product_Code" class="form-control input-xs Product_Code " onkeyup="fetch()" name="Product_Code[]" required>
</td>
<td ><input style="width:300px" type="text" id="Product_Name" class="form-control input-xs" name = "Prdtname[]" > </td>
<!--value="<?php echo $row['Product_Name']; ?>"-->
<td><input style="width:80px" type="text" id="Qty" onkeyup="movetoNext(this, 'addMore3')" class="form-control input-xs" name="Qty[]" required></td>
<td><input style="width:100px" type="text" id="Rate" class="form-control input-xs" value="" name="rate[]" required></td>
<td><input style="width:150px" type="text" id="Value" class="form-control input-xs" name="amount[]" ></td>
<th><span class="glyphicon glyphicon-plus"></span></th>
</tr>
</tbody>
</table>
Fetch code:
public function fetch()
{
$this->load->model('User_model');
$result = $this->User_model->fetch_name($_POST["code"]);
echo json_encode($result);
//echo 'hello'.$code;
}
Model code:
public function fetch_name($code)
{
$query = $this->db->query("select * FROM itemmaster where itcode = $code")->row_array();
return $query;
}
I am trying to fetch the product details by product code when the user hits tab key..what i have to alter to make the fetching available to all the rows of a table..Thanks in advance
You can use onchange like below
<input style="width:80px" type="text" id="Product_Code" class="form-control input-xs Product_Code " onchange="fetchdetails(this)" name="Product_Code[]" required>
fetchdetails function:
function fetchdetails(e) {
var code = e.value;
$.ajax({
type: "POST",
url: "<?php echo base_url();?>TipUp_Loan/fetch",
data: {
code: code
},
datatype: 'json',
success: function (data) {
var json = data,
obj = JSON.parse(json);
var prodName = $(e).closest('tr').find('#Product_Name');
$(prodName).val(obj.itemname);
var rate = $(e).closest('tr').find('#Rate');
$(rate).val(obj.salrate);
}
});
}
You can use it for dynamic rows, it will fetch the current row and populate the records.
We have a .aspx page with two HTML SELECT element and we want to load countries in one dropdownlist and load cities of a country in the other.
we are using entity framework to access data.
I tried PageMethods and &Ajax but I could not access my city dropdown from within a static web method. this is what we have so far:
<!-- Signup.aspx-->
<select id="cmb_Region" runat="server" onchange="GetCitiesOfRegion();" datatextfield="region_title" datavaluefield="region_id"></select>
<select runat="server" id="cmb_City" datatextfield="city_title" datavaluefield="city_id" class="ui dropdown"></select>
<script type="text/javascript">
function GetCitiesOfRegion(regionId)
{
$.ajax({
url:"Signup.aspx/GetCities",
type:"POST",
data:'{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert("success");
}
});
}
</script>
and this is code-behind code:
//Signup.aspx.cs
[WebMethod]
public static List<City> GetCities(int RegionId)
{
behbimeh_informationEntities db = new behbimeh_informationEntities();
return db.City.Where(i => i.region_id == RegionId).ToList();
}
Actually the code is not correct and I dont know how to pass the cmb_region selected value to the webmethod? and I dont know how to bind the cmb_city to the returned List of cities.
please share your knowledge. thanks...
To get cmb_Region value
var regionId = $('#<%= cmb_Region.ClientID %>').val();
To get cities by region and bind at client side
[WebMethod]
public static string GetCities(int RegionId)
{
behbimeh_informationEntities db = new behbimeh_informationEntities();
var cities= db.City.Where(i => i.region_id == RegionId).Select(item=>new { item.ValueField, item.TextField }).ToList();
return Newtonsoft.Json.JsonConvert.SerializeObject(cities);
}
<script type="text/javascript">
function GetCitiesOfRegion(regionId)
{
$.ajax({
url:"Signup.aspx/GetCities",
type:"POST",
data:'{"RegionId":'+regionId+'}',
success: function (r) {
var cities=JSON.parse(r.d);
var citiesOptions="";
for(var i=0;i<cities.length;i++){
citiesOptions+='<option value="'+cities[i].Value+'">'+cities[i].Text+'</option>';
}
$('#<%= cmb_City.ClientID %>').html(citiesOptions);
}
});
}
first you will need to clear the existing data, like so:
$('#cmb_city').empty();
next, you need to load the returned list to your ddl.
$.ajax({
url:"Signup.aspx/GetCities",
type:"POST",
data:'{"RegionId":'+$('#cmb_Region').val()+'}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
$.each(r, function() {
$('#cmb_city').append($('<option>').text(this.Name).attr('value', this.Id));
});
}
});
where Name and Id are your text and value fields respectively.
you will also probably need to send the selected region.
Here is your answer like how to bind data from database using Ajax in php
<!-- edit.php -->
<?php
include("config.php");
$id=$_REQUEST['id'];
echo $id;
$query=mysqli_query($con,"SELECT * FROM register r
INNER JOIN country c ON r.cuid = c.cuid
INNER JOIN state s ON r.sid = s.sid
INNER JOIN city ct ON r.cid = ct.cid where id='$id'");
while($r=mysqli_fetch_array($query))
{
$fn=$r['firstname'];
$add=$r['address'];
$gn=$r['gender'];
$hobby=$r['hobby'];
$h=explode(',',$hobby);
$q=array('reading','traveling','cricket','drawing');
$country=$r['cuid'];
$state=$r['sid'];
$city=$r['cid'];
echo $gn;
$edu= $r['education'];
$email=$r['email'];
$pass=$r['password'];
$conpass=$r['conpassword'];
$phno=$r['phoneno'];
}
?>
<html>
<head>
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#country').on('change',function(){
var countryID = $(this).val();
if(countryID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'cuid='+countryID,
success:function(html){
$('#state').html(html);
$('#city').html(html);
}
});
}else{
$('#state').html(html);
$('#city').html(html);
}
});
$('#state').on('change',function(){
var stateID = $(this).val();
if(stateID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'sid='+stateID,
success:function(html){
$('#city').html(html);
}
});
}else{
$('#city').html(html);
}
});
});
</script>
</head>
<body>
<form method="post" action="update.php">
<table border="1" align="center">
<caption>Edit user data</caption>
<tr>
<td>First name</td>
<td><input type="text" name="fn" value="<?php echo $fn;?>"></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="add" value="<?php echo $add;?>"></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="gn" value="male" <?php echo ($gn=='male')?'checked':'' ; ?> size="17">Male
<input type="radio" name="gn" value="female" <?php echo ($gn=='female')?'checked':'' ; ?> size="17">Female
</td>
</tr>
<tr>
<td>Hobby</td>
<td><input type="checkbox" name="hobby[]" value="reading" <?php if(in_array('reading',$h)){echo ("checked:'checked'");}?> >reading
<input type="checkbox" name="hobby[]" value="traveling" <?php if(in_array('traveling',$h)){echo ("checked:'checked'");}?> >traveling
<input type="checkbox" name="hobby[]" value="cricket" <?php if(in_array('cricket',$h)){echo ("checked:'checked'");}?> >cricket
<input type="checkbox" name="hobby[]" value="drawing" <?php if(in_array('drawing',$h)){echo ("checked:'checked'");}?> >drawing</td>
</tr>
<?php
$query = mysqli_query($con,"SELECT * FROM country");
//Count total number of rows
$rowCount = mysqli_num_rows($query);
?>
<td>Country</td>
<td><select name="country" id="country">
<option value="<?php echo $country;?>"><?php echo $country;?></option>
<?php
if($rowCount > 0)
{
while($row = mysqli_fetch_array($query))
{
echo '<option value="'.$row['cuid'].'">'.$row['country'].'</option>';
}
}
else
{
echo '<option value="">Country not available</option>';
}
?>
</select>
</td></tr>
<tr>
<td>State</td>
<td>
<select name="state" id="state">
<option value="<?php echo $state;?>"><?php echo $state;?></option>
</select>
</td></tr>
<tr>
<td>City</td>
<td>
<select name="city" id="city">
<option value="<?php echo $city;?>"><?php echo $city;?></option>
</select>
</td>
</tr>
<tr>
<td>Education</td>
<td><input type="text" name="edu" value="<?php echo $edu;?>"></td>
</tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php echo $email;?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="pass" value="<?php echo $pass;?>"></td>
</tr>
<tr>
<td>Confirm password</td>
<td><input type="text" name="conpass" value="<?php echo $conpass;?>"></td>
</tr>
<tr>
<td>Phone no</td>
<td><input type="text" name="phno" value="<?php echo $phno;?>"></td>
</tr>
<tr>
<td><input type="hidden" name="id" value="<?php echo $id;?>">
<input type="submit" name="update" value="update"></td>
</tr>
</table>
</form>
</body>
</html>
--------------------
<!--ajaxData.php-->
<?php
//Include database configuration file
include("config.php");
if(isset($_POST["cuid"]) && !empty($_POST["cuid"]))
{
//Get all state data
$query = mysqli_query($con,"SELECT * FROM state WHERE cuid = ".$_POST['cuid']."");
//Count total number of rows
$rowCount = mysqli_num_rows($query);
//Display states list
if($rowCount > 0)
{
echo '<option value="">Select state</option>';
while($row = mysqli_fetch_array($query))
{
echo '<option value="'.$row['sid'].'">'.$row['state'].'</option>';
}
}
else
{
echo '<option value="">State not available</option>';
}
}
if(isset($_POST["sid"]) && !empty($_POST["sid"]))
{
//Get all city data
$query = mysqli_query($con,"SELECT * FROM city WHERE sid =".$_POST['sid']."");
//Count total number of rows
$rowCount = mysqli_num_rows($query);
//Display cities list
if($rowCount > 0)
{
echo '<option value="">Select city</option>';
while($row = mysqli_fetch_array($query))
{
echo '<option value="'.$row['cid'].'">'.$row['city'].'</option>';
}
}
else
{
echo '<option value="">City not available</option>';
}
}
?>
I am selecting an item from a select-option tag in a table to populate records from a database to fill another input field, but unfortunately, it only works for the first table row. When I add another table row with jquery, it does not work in the new added table row.
<table class="table table-borderd table-hover">
<thead>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Discount %</th>
<th>Total</th>
<th><input type="button" class="btn btn-primary addmore" value="+"></th>
</tr>
</thead>
<tbody id="itemlist2" class="detailss">
<tr>
<td>
<select class="select-product form-control" name="product_name[]">
<option value="">
</option>
<?php
foreach ($product as $key ):
?>
<option value="<?php echo $key['id'] ?>">
<?php echo $key['product_name'] ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<input type="text" name="price[]" class="price form-control" value="">
</td>
<td><input type="text" name="quantity[]" class="form-control"></td>
<td><input type="text" name="discount[]" class="form-control"></td>
<td><input type="text" name="total[]" class="form-control"></td>
</tr>
</tbody>
</table>
The script that add new row to table
<script>
var i=$('#itemlist2 tr').length;
$(".addmore").on('click',function(){
html = '<tr>';
html += '<td><select class="select-product form-control" name="product_name[]"> <option value=""> </option><?php foreach ($product as $key ): ?><option value="<?php echo $key['id'] ?>"><?php echo $key['product_name'] ?></option><?php endforeach; ?></select></td>';
html += '<td><input type="text" name="price[]" class="price form-control" value=""></td>';
html += ' <td><input type="text" name="quantity[]" class="form-control"></td>';
html += '<td><input type="text" name="discount[]" class="form-control"></td>';
html += '<td><input type="text" name="total[]" class="form-control"></td>';
html += '</tr>';
$('#itemlist2').append(html);
i++;
});
</script>
The onchange function with ajax
<script>
$(function() {
$(document).on('change', '.select-product', function(){
$(this).change(function(){
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax({
type: "GET",
url: "<?php echo site_url('/product/view_data'); ?>",
data: dataString,
cache: false,
success: function(html){
$('.price').parent().parent().find('.price').val(html);
}
});
});
});
});
</script>
Thanks for your time!
Use delegate for dynamically added element. For example
$(document).delegate( ".select-product", "change", function() {
$(this).change(function(){
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax({
type: "GET",
url: "<?php echo site_url('/product/view_data'); ?>",
data: dataString,
cache: false,
success: function(html){
alert(html);
// $("#price").val(html);
}
});
});
});
});
I hope it will help you.
New added elements does not have the event binding.
The quickest fix is just change your event binding code from
$('input').change(function () {
// Do some stuff.
});
to
$(document).on('change', 'input', function() {
// Do some stuff.
});
Check these following lines:
html += '<td><select class="select-product form-control" id="product" ....
and
var id=$("#product").val();
You are assigning an id to multiple rows and trying to get the values using id which is unique. That's why you are getting the data for first row only.
To solve this, refer it using class and $(this) to get the value of current instance.
I have an HTML form which gets some text data from the user. I want to insert that into my database and stay on the same form so that another row can be created in the database. I have the php working fine if I call it from the form using action='includes/addUser.php' but that then leaves the browser on the addUser.php page which doesnt display anything. I had thought I could use ajax to not change the display but the php does not seem to get called. If I change the name of the php file in the ajax call I do see an error.
<div id="addUserFormDivID">
<!-- <form id='addUserFormID' method='post' action='includes/addUser.php'> -->
<form id='addUserFormID' method='post' onSubmit='javascript:addUser()'>
Add User<br /><br />
<table>
<tr>
<td align="right">Full name:</td>
<td align="left"><input type="text" name="fullName" /></td>
</tr>
<tr>
<td align="right">Nickname:</td>
<td align="left"><input type="text" name="nickName" /></td>
</tr>
<tr>
<td align="right">Email:</td>
<td align="left"><input type="text" name="email" /></td>
</tr>
<tr>
<td align="right">Phone:</td>
<td align="left"><input type="text" name="phone" /></td>
</tr>
<tr>
<td align="right">Postal Address:</td>
<td align="left"><input type="text" name="address" /></td>
</tr>
<tr>
<td align="right">Postcode:</td>
<td align="left"><input type="text" name="postcode" /></td>
</tr>
</table>
<input type="submit" name="submitAddUser" value="Add User" style="float:right">
</form>
</div>
<script type="text/javascript">
function addUser()
{
console.log("javascript addUser()");
$.ajax
({
type: "POST",
url: "includes/addUser.php",
//data: '1',
success: function()
{
alert("User added");
}
}); // Ajax Call alert("hello");
}
addUser.php:
<?php
include_once 'db_connect.php';
include_once 'functions.php';
//sec_session_start();
debug_to_console("addUser.php");
$fullName = $_POST[fullName];
$nickName = $_POST[nickName];
$email = $_POST[email];
$phone = $_POST[phone];
$address = $_POST[address];
$postcode = $_POST[postcode];
$stmt = mysqli_prepare($mysqli, "INSERT INTO Person (FullName, NickName, Email, Phone, PostalAddress, Postcode) VALUES (?, ?, ?, ?, ?, ?)");
if ($stmt === false)
{
trigger_error('Statement failed! ' . htmlspecialchars(mysqli_error($mysqli)), E_USER_ERROR);
}
$bind = mysqli_stmt_bind_param($stmt, "ssssss", $fullName, $nickName, $email, $phone, $address, $postcode );
if ($bind === false)
{
trigger_error('Bind param failed!', E_USER_ERROR);
}
$exec = mysqli_stmt_execute($stmt);
if ($exec === false)
{
trigger_error('Statement execute failed! ' . htmlspecialchars(mysqli_stmt_error($stmt)), E_USER_ERROR);
}
//printf ("New Record has id %d.\n", mysqli_insert_id($mysqli));
mysqli_stmt_close($stmt);
echo "done addUser";
?>
with the action='includes/addUser.php' line not commented out (and the onSubmit commented out) then it works as I want up to displaying a blank page
With the onSubmit line active instead, the javascript addUser function is called ("javascript addUser()" is output to the console and the alert is shown with "User added") but nothing in the addUser.php file seems to be run. If I include_once a nonexistent file at the start of addUser.php, I dont see an error.
You need to include the data of your form in the request. Also note that it's generally considered best practice to hook your events up in JavaScript. With that in mind try this:
<form id="addUserFormID" method="post" action="include/addUser.php">
<!-- rest of your inputs -->
</form>
$(function() {
$('#addUserFormID').submit(function(e) {
e.preventDefault(); // stop the normal form submission
$.ajax({
type: this.method,
url: this.action,
data: $(this).serialize(),
success: function() {
alert("User added");
}
});
});
});
After url use:
url: "includes/addUser.php",
data : $("#addUserFormID").serialize(),
type: "POST",
.......
I'm caught in a set of twisting codes. I've a table in a form which consists of all the information from one table say emp_info. I am not including all the mysql query and db connection but just suppose this table has fetched information from emp_info table from my database. Example:
<table align="center">
<form name="f1" action="update.php" method="post">
<tr>
<td>Enter name : </td><td><input type="text" name="ename" id="field1"
disabled="disabled" /></td><td><input id="myCheckBox1" type="checkbox"
onclick="enableText1(this.checked, 'field1');" />
</td>
</tr>
<tr>
<td>Enter Address : </td><td><input type="text" name="address" id="field2"
disabled="disabled" /></td><td><input id="myCheckBox2" type="checkbox"
onclick="enableText2(this.checked, 'field2');" /></td>
</tr>
<tr>
<td><input type=""submit value="submit"/></td>
</tr>
</form>
</table>
and following is the respective JAVASCRIPT written in the HEAD section:
<script type="text/javascript">
function enableText1(checkBool, textID)
{
text1 = document.getElementById(textID);
//Disable the text field
text1.disabled = !checkBool;
//Clear value in the text field
if (!checkBool) { text1.value = ''; }
}
function enableText2(checkBool, textID)
{
text2 = document.getElementById(textID);
//Disable the text field
text2.disabled = !checkBool;
//Clear value in the text field
if (!checkBool) { text2.value = ''; }
}
</script>
I want user to check the checkbox to enable the textbox to edit it. What can a user do with it? He can check the checkbox to edit it and when he unchecks it once again textbox will be disabled. That means, what he edited in the checkbox is going to be locked. To prevent him from doing it; I'm setting the textbox to empty; once he unchecks the checkbox. It's working up to it. My real problem starts from here. when the textbox is disabled and he submits the records to update, it throws an error while accepting the value using POST method ($name=$_POST['name']) in update.php:
Notice: Undefined variable: address in C:\xampp\htdocs\xampp\Test\HRMS\try\chcking with checkboxes\update.php on line 4
My main intention is to update the record into the temporary table. When a record is submitted using disabled textbox or empty textbox; in that case I would like to fetch its value from the old table and store it into the temporary table. I do not know how clear I am but accepting some support from enthusiastic master's in coding here. Thanks in advance.
please check my actual code. I am including both the pages below :
<?php
session_start();
if(!$_SESSION['logged'])
{
header("Location: login.php");
exit;
}
echo 'Welcome, '.$_SESSION['user'];
//echo 'Welcome, '.$_SESSION['email'];
//echo 'Welcome, '.$_SESSION['eid'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function enableText1(checkBool, textID)
{
text1 = document.getElementById(textID);
//Disable the text field
text1.disabled = !checkBool;
//Clear value in the text field
if (!checkBool) { text1.value = ''; }
}
</script>
</head>
<body>
</body>
</html>
<?php
$user=$_SESSION['user'];
$email=$_SESSION['email'];
$eid=$_SESSION['eid'];
echo "<br>";
//echo $email;
//echo $eid;
//echo $user;
$con = mysql_connect("localhost","mars","mars");
if (! $con)
die(mysql_error());
mysql_select_db("marsweb",$con);
mysql_query(" UPDATE login_info SET user_staus=1 WHERE username='$email'");
$query="SELECT * FROM emp_info WHERE eid='$eid'";
//echo "$query";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$userid=mysql_result($result,$i,"eid");
$name=mysql_result($result,$i,"ename");
$password=mysql_result($result,$i,"password");
$address=mysql_result($result,$i,"address");
$source=mysql_result($result,$i,"source");
$salary=mysql_result($result,$i,"salary");
$zip=mysql_result($result,$i,"zip");
$mobile=mysql_result($result,$i,"mobile");
$email=mysql_result($result,$i,"email");
?>
<div class="go_right">
<table width="100" cellpadding="10" cellspacing="0" border="2" align="center">
<form action="change_record1.php" method="post">
<tr>
<td>Employee ID</td><td><input type="text" name="userid" value="<?php echo "$userid" ?>" readonly></td>
</tr>
<tr>
<td>Name:</td><td><input type="text" name="name" value="<?php echo "$name"?>" readonly></td>
</tr>
<!--<tr>
<td>Password: </td><td><input type="text" name="password" value="<?php echo "$password"?>" ></td>
</tr>-->
<tr>
<td>Address:</td><td> <input type="text" name="address" value="<?php echo "$address"?>" id="field1" dissabled="disabled" /></td>
<td><input id="myCheckBox1" type="checkbox" onClick="enableText1(this.checked, 'field1');" /></td>></td>
</tr>
<tr>
<td>Source: </td><td><input type="text" name="source" value="<?php echo "$source"?>"></td>
</tr>
<tr>
<td>Salary: </td><td><input type="text" name="salary" value="<?php echo "$salary"?>" readonly></td>
</tr>
<tr>
<td>Mobile:</td><td> <input type="text" name="mobile" value="<?php echo "$mobile"?>"></td>
</tr>
<tr>
<td>Zip: </td><td><input type="text" name="zip" value="<?php echo "$zip"?>"></td>
</tr>
<tr>
<td>Email: </td><td><input type="text" name="email" value="<?php echo "$email"?>" readonly></td>
</tr>
<tr style="border:#FFF";>
<td><input type="Submit" value="Update"></td>
</tr>
</form>
</table>
<?php
++$i;
}
?>
and the php page which will update the temporary table is given below...
<?php
session_start();
if(!$_SESSION['logged'])
{
header("Location: login.php");
exit;
}
echo 'Welcome, '.$_SESSION['user'];
echo "<br>";
echo "<br>";
?>
<?php
$userid=$_POST['userid'];
//$name=$_POST['name'];
//$password=$_POST['password'];
if(isset($_POST['address']))
$address=$_POST['address'];
$source=$_POST['source'];
$salary=$_POST['salary'];
$mobile=$_POST['mobile'];
$zip=$_POST['zip'];
$email=$_POST['email'];
$con = mysql_connect("localhost","mars","mars");
if (! $con)
die(mysql_error());
mysql_select_db("marsweb",$con);
//echo $userid; echo "<br>";
echo $address; echo "<br>";
if($address=="")
{
$query1="select address from `emp_info` where email='$email'";
$fetched1=mysql_query($query1);
while($record1=mysql_fetch_assoc($fetched1))
{
while(each($fetched1))
{
$address=$record1["address"];
}
}
}
echo $address;
mysql_query("UPDATE temp_emp_info SET eid='$userid' , address='$address' , source='$source' , mobile='$mobile' , zip='$zip' WHERE eid='$userid'");
echo "<br>";echo "<br>";echo "<br>";
echo "<center><h2>Record updated</h2></center><br><br>";
?>
When a field is marked "disabled" it doesn't get submitted to the server, so the value is lost. You either need to adapt your server side code to be aware of the possibility that the textbox is unset, or use readonly="readonly" instead of disabled="disabled" to make the text field uneditable. Read only controls are still submitted to the server, they just can't be edited by the user.