i have a problem in updating the records...
it did'nt work... wats the prob with my update code...
i edit and when i update record nothing happens...
can any1 help me....
thnx and godbless!

<?php
header("location: index.php");
include("conn.php");
$mode=$_GET["mode"];
if($mode=="add") {
$MachineNo=$_POST["MachineNo"];
$MnfgDate=$_POST["MnfgDate"];
$sql="insert into $PRD(MachineNo,MnfgDate) values('$MachineNo','$MnfgDate')";
$result=mysql_query($sql) or die(mysql_error());


} elseif($mode=="update") {
$MachineNo=$_POST["MachineNo"];
$MnfgDate=$_POST["MnfgDate"];
$sn=$_POST["MnfgDate"];
$sql="update $PRD set MachineNo='$MachineNo',MnfgDate='$MnfgDate' where MnfgDate='$sn'";
//echo $sql;
$result=mysql_query($sql) or die(mysql_error());
header("location: index.php");
}



error_reporting(E_ALL);
?>

Try something like this:

<?php
error_reporting(E_ALL);

header("location: index.php");
include("conn.php");
$mode=$_GET["mode"];
if($mode=="add") {
$MachineNo=$_POST["MachineNo"];
$MnfgDate=$_POST["MnfgDate"];
$PRD='tablename'; //make sure $RPD is assigned to the table name
$sql="insert into $PRD(MachineNo,MnfgDate) values('".
mysql_real_escape_string($MachineNo)."','".mysql_real_escape_string($MnfgDate)."')";
$result=mysql_query($sql) or die(mysql_error());


} elseif($mode=="update") {
//use stripslashes if magicquotes are on.
$MachineNo=stripslashes($_POST["MachineNo"]);
$MnfgDate=stripslashes($_POST["MnfgDate"]);
$sn=stripslashes($_POST["MnfgDate"]);
$sql="update $PRD set MachineNo='".mysql_real_escape_string($MachineNo)."',MnfgDate='".
mysql_real_escape_string($MnfgDate)."' where MnfgDate='".mysql_real_escape_string($sn)."'";
//echo $sql;
$result=mysql_query($sql) or die(mysql_error());
header("location: index.php");
}
?>

$sql="update $PRD set MachineNo='$MachineNo',MnfgDate='$MnfgDate' where MnfgDate='$sn'"; I think u need to check the datatype for column MnfgDate. is it a varchar or date? if the datatype is date, then i think u need to make sure that $sn is also in a date format.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.