hii
i hav a code in php which makes changes in mysql d/b ..the code adds the values instead i want that the code should overwrite them ..please tell me what changes to make. I'll be happy to provide if u need any details abt working the program if it is neccessary to make modifications in the code. I am posting the code below
Thanks in advance
nikunj
****************************************************************
<? include('application_top.php');?>
<SCRIPT LANGUAGE="JavaScript">
<!--
function combo1(t1)
{
var loc2=document.frm.loc.options[t1].text;
document.frm.locat.value=loc2;
}
//-->
</SCRIPT>
<BODY>
<FORM NAME="frm" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<?$qr3=mysql_query("Select * from location");
?>
<table border="0" cellspacing ="0" cellpadding ="0"r">
<tr>
<td>Select the MMU<Select name="loc" onChange="frm.submit();">
<option>Select the Location
<?
while($rsw=mysql_fetch_array($qr3))
{
if($rsw["location"]==$_POST["loc"])
{
?>
<option selected><? echo $rsw["location"];?>
<?
}
else
{
?>
<option><? echo $rsw["location"];?>
<?
}
}
?>
</select>
</td>
<?
$lc=$_POST["loc"];
if($lc)
{
$medtb="medicine_".$lc;
$qr2=mysql_query("select * from ".$medtb." order by medicine");
}
?>
<td>Select the Medicine<Select name="med" onChange="frm.submit();">
<option>Select the Medicine
<?
while($rsw2=mysql_fetch_array($qr2))
{
if($rsw2["medicine"]==$_POST["med"])
{
?>
<option selected><? echo $rsw2["medicine"];?>
<?
}
else
{
?>
<option><? echo $rsw2["medicine"];?>
<?
}
}
?>
</select>
</td>
<?
$med=$_POST["med"];
$qr5=mysql_query("Select * from mth");
?>
<td>Select the Month<Select name="mth" onChange="frm.submit();">
<option>Select the Month
<?
while($rsw5=mysql_fetch_array($qr5))
{
if($rsw5["month"]==$_POST["mth"])
{
?>
<option selected><? echo $rsw5["month"];?>
<?
}
else
{
?>
<option><? echo $rsw5["month"];?>
<?
}
}
?>
</select>
</td>
</TR>
<?
$mon=$_POST["mth"];
if($mon=='January')
{
$dt='2003-01-31';
}
if($mon=='February')
{
$dt='2003-02-28';
}
if($mon=='March')
{
$dt='2003-03-31';
}
if($mon=='April')
{
$dt='2003-04-30';
}
if($mon=='May')
{
$dt='2003-05-31';
}
if($mon=='June')
{
$dt='2003-06-30';
}
if($mon=='July')
{
$dt='2003-07-31';
}
if($mon=='August')
{
$dt='2003-08-31';
}
if($mon=='September')
{
$dt='2003-09-30';
}
if($mon=='October')
{
$dt='2003-10-31';
}
if($mon=='November')
{
$dt='2003-11-30';
}
if($mon=='December')
{
$dt='2003-12-31';
}
?>
<tr></tr>
</table>
<table>
<TR><TD>Quantity Purchased</td>
<td><input type="text" name="qpur" value="0.00"></td></tr>
<tr><td><Input type="Submit" name="Submit" value="Go!">
</td></tr>
<?
$sb=$_POST["Submit"];
$qpur1=$_POST["qpur"];
$dqty=0;
$drate=0;
$donated=0;
if($sb)
{
mysql_query("insert into med_cons_report values('','".$lc."','".$dt."','".$med."','".$qpur1."','".$donated."','".$lc."', NOW(), '', '' )");
}
mysql_free_result;
?>
</TABLE>
</BODY>
modifying a php code
Moderator: General Moderators
Code: Select all
<? include('application_top.php');?>
<SCRIPT LANGUAGE="JavaScript">
<!--
function combo1(t1)
{
var loc2=document.frm.loc.options[t1].text;
document.frm.locat.value=loc2;
}
//-->
</SCRIPT>
<BODY>
<FORM NAME="frm" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<?$qr3=mysql_query("Select * from location");
?>
<table border="0" cellspacing ="0" cellpadding ="0"r">
<tr>
<td>Select the MMU<Select name="loc" onChange="frm.submit();">
<option>Select the Location
<?
while($rsw=mysql_fetch_array($qr3))
{
if($rsw["location"]==$_POST["loc"])
{
?>
<option selected><? echo $rsw["location"];?>
<?
}
else
{
?>
<option><? echo $rsw["location"];?>
<?
}
}
?>
</select>
</td>
<?
$lc=$_POST["loc"];
if($lc)
{
$medtb="medicine_".$lc;
$qr2=mysql_query("select * from ".$medtb." order by medicine");
}
?>
<td>Select the Medicine<Select name="med" onChange="frm.submit();">
<option>Select the Medicine
<?
while($rsw2=mysql_fetch_array($qr2))
{
if($rsw2["medicine"]==$_POST["med"])
{
?>
<option selected><? echo $rsw2["medicine"];?>
<?
}
else
{
?>
<option><? echo $rsw2["medicine"];?>
<?
}
}
?>
</select>
</td>
<?
$med=$_POST["med"];
$qr5=mysql_query("Select * from mth");
?>
<td>Select the Month<Select name="mth" onChange="frm.submit();">
<option>Select the Month
<?
while($rsw5=mysql_fetch_array($qr5))
{
if($rsw5["month"]==$_POST["mth"])
{
?>
<option selected><? echo $rsw5["month"];?>
<?
}
else
{
?>
<option><? echo $rsw5["month"];?>
<?
}
}
?>
</select>
</td>
</TR>
<?
$mon=$_POST["mth"];
if($mon=='January')
{
$dt='2003-01-31';
}
if($mon=='February')
{
$dt='2003-02-28';
}
if($mon=='March')
{
$dt='2003-03-31';
}
if($mon=='April')
{
$dt='2003-04-30';
}
if($mon=='May')
{
$dt='2003-05-31';
}
if($mon=='June')
{
$dt='2003-06-30';
}
if($mon=='July')
{
$dt='2003-07-31';
}
if($mon=='August')
{
$dt='2003-08-31';
}
if($mon=='September')
{
$dt='2003-09-30';
}
if($mon=='October')
{
$dt='2003-10-31';
}
if($mon=='November')
{
$dt='2003-11-30';
}
if($mon=='December')
{
$dt='2003-12-31';
}
?>
<tr></tr>
</table>
<table>
<TR><TD>Quantity Purchased</td>
<td><input type="text" name="qpur" value="0.00"></td></tr>
<tr><td><Input type="Submit" name="Submit" value="Go!">
</td></tr>
<?
$sb=$_POST["Submit"];
$qpur1=$_POST["qpur"];
$dqty=0;
$drate=0;
$donated=0;
if($sb)
{
mysql_query("insert into med_cons_report values('','".$lc."','".$dt."','".$med."','".$qpur1."','".$donated."','".$lc."', NOW(), '', '' )");
}
mysql_free_result;
?>
</TABLE>
</BODY>Have you looked into ALTER TABLE? In addition, change the HTML to lowercase and possibly make it XHTML compatible.
-
TheBentinel.com
- Forum Contributor
- Posts: 282
- Joined: Wed Mar 10, 2004 1:52 pm
- Location: Columbus, Ohio
Re: modifying a php code
Use UPDATE instead of INSERT. UPDATE expects you to tell it which record to update, do you only have one record in your table? If you need to update a specific record, give it a WHERE clause like you would with a SELECT.nnikunjj wrote:Code: Select all
if($sb) { mysql_query("insert into med_cons_report values('','".$lc."','".$dt."','".$med."','".$qpur1."','".$donated."','".$lc."', NOW(), '', '' )"); }
UPDATE syntax: http://www.simple-sw.com/sql-update.htm