Problem with update script.
I am creating a form with insert, retrieve and update. Here insert and retrieve scripts are working good, but the update script is not working. did i made anything wrong in the script. Please guide me.
here are the three php scripts.
JobNotes.php (for retrieve)
<html>
<head>
<style type="text/css">
p.three
{
border-bottom-color:#CCC;
border-bottom-style:solid;
border-width:1px;
}
</style>
<script type="text/javascript">
function open_win()
{
window.open("AddJob.php",'','width=480,height=150, left=750,top=150');
}
</script>
<SCRIPT language="JavaScript">
function editwin()
{
window.open('Edit.php','jav','width=480,height=150 ,left=750,top=150');
}
</SCRIPT>
</head>
<body>
<table width="100%" border="0">
<tr>
<td>Job Notes</td>
<td><input type=button value="AddNew" onClick="open_win()"></td>
</tr>
</table>
<br>
<br>
<?php
mysql_connect('localhost','root','');
@mysql_select_db('taskmanagement') or die( "Unable to select database");
$query="SELECT * FROM addjob ORDER BY id";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<?php
$i=0;
while ($i<$num) {
$f1=mysql_result($result,$i,"add_job");
?>
<table width="75%">
<tr>
<td width="81%">
<font face="Arial, Helvetica, sans-serif" style="border-bottom-color:#C03"><p class="three"><?php echo $f1; ?></p>
</font>
</td>
<td width="3%">
<a href="javascript:editwin()"=<?php echo $f1['id']; ?>"><img src="edit.gif" width="16" height="16" hspace="0" vspace="0" border="0"></a>
</td>
</tr>
</table>
<?php
++$i;
}
?>
</body>
</html>
AddJob.php (for insert)
<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "taskmanagement";
$db_table = "addjob";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
?>
<html>
<head>
<title>Add Notes</title>
<script type="text/javascript">
function RefreshParentWindow()
{
if (window.opener && !window.opener.closed)
{
window.opener.location.reload();
self.close();
}
}
</script>
</head>
<body OnLoad="document.ad_A.addJob.focus();"">
<?php
if (isset($_REQUEST['Submit'])) {
$sql = "INSERT INTO $db_table(add_job) values ('".mysql_real_escape_string(stripslashes($_REQUES T['addJob']))."')";
if($result = mysql_query($sql ,$db)) {
} else {
echo "ERROR: ".mysql_error();
}
} else {
?>
<form method="post" action="" name="ad_A">
Add Notes:<br>
<textarea name="addJob" cols="50" rows="5" class="add"></textarea>
<input type="submit" name="Submit" value="OK" onClick="RefreshParentWindow()">
</form>
<?php
}
?>
</body>
</html>
Edit.php (for update)
<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "taskmanagement";
$db_table = "addjob";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
?>
<html>
<head>
<title>Edit Notes</title>
<script type="text/javascript">
function RefreshParentWindow()
{
if (window.opener && !window.opener.closed)
{
window.opener.location.reload();
self.close();
}
}
</script>
</head>
<body OnLoad="document.ad_E.edit.focus();"">
<?php
$edit=$_POST[edit];
if (isset($_REQUEST['Submit'])) {
$sql = "update addjob set add_job='$edit' where id='$id'";
if($result = mysql_query($sql ,$db)) {
} else {
echo "ERROR: ".mysql_error();
}
} else {
?>
<form method="post" action="" name="ad_E">
Edit Notes:<br>
<textarea name="edit" cols="50" rows="5" class="add"></textarea>
<input type="submit" name="Submit" value="OK" onClick="RefreshParentWindow()">
</form>
<?php
}
?>
</body>
</html>
Thanks.
|