hi,im having a problem with my code.im trying to edit data that im retrieving from my database tables.but im unable to submit the data after editing it.my code is shown below
<?php
require_once "../inc/functions.php";
require_once "../inc/vars.inc.php";
sessionCheck();
session_start();
$old_sessionid = session_id(); //i've added these lines
session_regenerate_id(); //i've added these lines
$new_sessionid = session_id(); //i've added these lines
function getdsgType(){
global $desig;
$output = '<select name="dsgn" id="dsgn">';
$output .= '<option value="">Designation</option>';
foreach($desig as $k=> $v){
if($_POST['dsgn'] == $k){
$output .= '<option value="'.$k.'" selected>'.$v.'</option>';
}else{
$output .= '<option value="'.$k.'">'.$v.'</option>';
}
}
$output .= '</select>';
return $output;
}
?>
<?php include_once "admin_templates/case_header.php"; ?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$query="select * from designation where designation='Minister'";
$exe=caseQuery($query);
if(mysql_num_rows($exe))
{
$output ='<table border="1">
<tr><td>Name</td><td>Designation</td><td>Date of Appointment</td><td>Phone Office</td><td>Mobile</td><td>Residence</td><td>District</td><td>Taluka</td>
<td>Panchayat Name</td><td>Panchayat Address</td><td>Edit</td></tr>';
$res=@mysql_fetch_object($exe);
$id=$res->sr_no;
$output .='<tr><td>'.$res->name.'</td><td>'.$res->designation.'</td><td>'.$res->dte.'</td><td>'.$res->ph_o.'</td><td>'.$res->ph_m.'</td><td>'.$res->ph_r.'</td><td>'.$res->district.'</td><td>'.$res->taluka.'</td><td>'.$res->pan_name.'</td><td>'.$res->pan_addr.'</td><td><a href="info.php?cmd=edit&id=$id">Edit</a></td></tr>';
}
$output .= '</table>';
echo "$output";
if($_GET["cmd"]=="edit")
{
$sql="select * from designation where sr_no='".$id."'";
$resl = caseQuery($sql);
$result=mysql_fetch_array($resl);
$id=$result["sr_no"];
$name=$result["name"];
$dsg=$result["designation"];
$dt=$result["dte"];
$ph_o=$result["ph_o"];
$ph_m=$result["ph_m"];
$ph_r=$result["ph_r"];
echo "<form ENCTYPE=\"multipart/form-data\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" name=\"src_frm\">";
echo "<input type=\"hidden\" value=\"".$result["sr_no"]."\" maxlength=\"64\" readonly name=\"id\" size=\"25\" /><br />";
echo "Name:";
echo "<input type=\"text\" value=\"".$result["name"]."\" maxlength=\"64\" name=\"name\" size=\"25\" /><br />";
echo "<br/>";
echo "Designation:";
$query=caseQuery("select designation from dsg");
echo "<select name='dsgn' ><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($query)) {
echo "<option value='$noticia[designation]'>$noticia[designation]</option>";
}
echo "</select>";
echo "<br/>";
echo "<br/>";
echo "Phone office:";
echo "<input type=\"text\" value=\"".$result["ph_o"]."\" maxlength=\"64\" name=\"office\" size=\"25\" /><br />";
echo "<br/>";
echo "Mobile:";
echo "<input type=\"text\" value=\"".$result["ph_m"]."\" maxlength=\"64\" name=\"mobile\" size=\"25\" /><br />";
echo "<br/>";
echo "Residence:";
echo "<input type=\"text\" value=\"".$result["ph_r"]."\" maxlength=\"64\" name=\"res\" size=\"25\" /><br />";
echo "<br/>";
echo "<button type=\"submit\" name=\"submit\">Update</button>";
echo "</form>";
echo "PLEASE LEAVE THE MOBILE NUMBER AND RESIDENCE NUMBER FIELD BLANK IF THERE IS NO NUMBER.<br/>";
if($_POST['submit']){
$id=escape($_POST['id']);
$name = escape($_POST['name']);
$desg = escape($_POST['dsgn']);
$ph_o= escape(trim($_POST['office']));
$ph_mob = escape($_POST['mobile']);
$ph_res = escape($_POST['res']);
echo "$id";
$errCnt = 0;
if(!$name)
{
$msg[] = "<h5>PLEASE ENTER A NAME</h5>";
$errCnt++;
}
else
if(!ctype_alpha($name))
{$msg[] = "<h5>YOU CAN ENTER ONLY ALPHABETS</h5>";
$errCnt++;
}
if(!$desg)
{
$msg[] = "<h5>PLEASE SELECT A DESIGNATION</h5>";
$errCnt++;;
}
if(!$ph_o)
{
$msg[] = "<h5>PLEASE ENTER THE OFFICE PHONE NUMBER</h5>";
$errCnt++;
}
else
if(!is_numeric($ph_o))
{
$msg[] = "<h5>THE OFFICE PHONE NUMBER CAN ONLY HAVE NUMBERS</h5>";
$errCnt++;
}
if(!$ph_mob)
{
$ph_mob="---- ";
}
else if(!is_numeric($ph_mob))
{
$msg[] = "<h5>THE MOBILE NUMBER CAN ONLY HAVE NUMBERS</h5>";
$errCnt++;
}
if(!$ph_res)
{
$ph_res="----";
}
else if(!is_numeric($ph_res))
{
$msg[] = "<h5>THE RESIDENCE NUMBER CAN ONLY HAVE NUMBERS</h5>";
$errCnt++;
}
$check="SELECT * FROM dsg, designation WHERE dsg.dsg_id BETWEEN 1 AND 7 AND designation.pan_name='".$vil_n."'
AND dsg.designation = designation.designation";
$chk=caseQuery($check);
if(mysql_num_rows($chk))
{
$message= "you already have a entry for this panchayat";
}
if($errCnt == 0 && !message){
$sql='UPDATE `designation` SET `name`="'.$name.'",`designation`="'.$desg.'",`ph_o`="'.$ph_o.'", `ph_m`="'.$ph_mob.'",`ph_r`="'.$ph_res.'" WHERE sr_no="'.$id.'"';
$dist = caseInsertQuery($sql);
if($dist)
{
$ms= "<b>THE DATA HAS BEEN ADDED SUCCESFULLY</b>";
}
else
{
$ms= "<b>THE DATA COULD NOT BE ADDED</b>";
}
}
else
{
$msgs = addslashes(@implode("<br>",$msg));
}
}
echo "$msgs";
echo "$ms";
echo "$message";
}
?>
</body>
</html>
please tell me where i m going wrong!