Dear all,
I would like to update the group of data which are in turn stored in mysql database.
delete function can work but the return value of the update function is not incorrect. Please htlp me revise the following program,thanks
Simon
-------------------------------------
<?if ($submit){
$db=mysql_connect("localhost","","");
mysql_select_db("school",$db);
$NoDelete=count($delete);
$NoUpdate=count($update);
for($i=0;$i<$NoDelete;$i++){
$sql="delete from news where id='$delete[$i]'";
$result=mysql_query($sql);
}
for($i=0;$i<$NoUpdate;$i++){
echo $e4;
bdate="b".$update[$i];
edate="e".$update[$i];
pdate="p".$update[$i];
content="con".$update[$i];
$sql="delete from news where id='$update[$i]'";
$result=mysql_query($sql);
$sql="insert into news(bdate,edate,pdate,content) values('$bdate','$edate','$pdate','$content')";
$result=mysql_query($sql);
}
echo" Thanks, the news information has been update!";
}else{
?>
<HEAD>
<meta http-equiv="expires" content="0">
</HEAD>
<script language="JavaScript">
function CheckForm()
{
return true;
}
</script>
<body background="" bgproperties="fixed" >
<p> <FONT color=blue face=Arial size=3><strong>Update and Delete News</strong>
</FONT></P>
<?
$db=mysql_connect("localhost","","");
mysql_select_db("school",$db);
$sql="select * from news order by pdate desc";
$result=mysql_query($sql,$db);
?>
<form method="post" action="<?echo $PHP_SELF;?>"name="form" onSubmit="return CheckForm()">
<table border=1 cellspacing=0 bordercolorlight="#5e5e00" bordercolordark="#ffffec" cellpadding="2" width="560" height="12">
<tr bgcolor="#eeeee">
<td bgcolor="ccccff" height="12" width="41" align="middle"><font face="Arial, Helvetica, sans-serif" size="2"><b>Delete</b></font></td>
<td bgcolor="ccccff" height="12" width="45" align="middle"><font color="#000000" face="Arial" size="2"><b><font face="Arial, Helvetica, sans-serif">Update</font></b></font></td>
<td bgcolor="ccccff" height="12" width="70" align="middle"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">Post
Date</font></strong></font></td>
<td bgcolor="ccccff" height="12" width="70" align="middle"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">BeginOfDate</font></strong></font></td>
<td bgcolor="ccccff" height="12" width="79" align="middle"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">EndOfDate</font></strong></font></td>
<td bgcolor="ccccff" height="12" width="313"
align="middle">
<div align="center"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">Contents</font></strong></font></div>
</td>
</tr>
<?
if (mysql_num_rows($result)>0):
while (list($id,$pdate,$bdate,$edate,$content)=mysql_fetch_row($result)):
?>
<tr>
<td height="12" width="41" valign="top">
<input type="checkbox" name="delete[]" value=http://www.phpbuilder.com/board/archive/index.php/"<?echo $id ?>">
</td>
<td height="12" width="45" valign="top">
<input type="checkbox" name="update[]" value="<?echo $id ?>">
</td>
<td height="12" width="70" valign="top">
<input type="text" name="p<?echo $id ?>"readonly value="<?echo $pdate ?>" size="10" maxlength="10">
</td>
<td height="12" width="70" valign="top">
<input type="text" name="b<?echo $id ?>"value="<?echo $bdate ?>" size="10" maxlength="10">
</td>
<td height="12" width="79" valign="top">
<input type="text" name="e<?echo $id ?>"value="<?echo $edate ?>" size="10" maxlength="10">
</td>
<td height="12" width="313" valign="top">
<textarea name="con<?echo $id ?>" COLS="50"><?echo $content ?></textarea>
</td>
<?endwhile;?>
</table>
<input type="submit" name="submit" value="submit">
</form>
<?else:?>
<font face="Arial, Helvetica, sans-serif"size="2">No any message</font>
<input type="submit" name="Submit" value="Back" onClick ="javascript:self.location.href='upnews.php'" >
<?
endif
?>
</body>
<?
}?>
I would like to update the group of data which are in turn stored in mysql database.
delete function can work but the return value of the update function is not incorrect. Please htlp me revise the following program,thanks
Simon
-------------------------------------
<?if ($submit){
$db=mysql_connect("localhost","","");
mysql_select_db("school",$db);
$NoDelete=count($delete);
$NoUpdate=count($update);
for($i=0;$i<$NoDelete;$i++){
$sql="delete from news where id='$delete[$i]'";
$result=mysql_query($sql);
}
for($i=0;$i<$NoUpdate;$i++){
echo $e4;
bdate="b".$update[$i];
edate="e".$update[$i];
pdate="p".$update[$i];
content="con".$update[$i];
$sql="delete from news where id='$update[$i]'";
$result=mysql_query($sql);
$sql="insert into news(bdate,edate,pdate,content) values('$bdate','$edate','$pdate','$content')";
$result=mysql_query($sql);
}
echo" Thanks, the news information has been update!";
}else{
?>
<HEAD>
<meta http-equiv="expires" content="0">
</HEAD>
<script language="JavaScript">
function CheckForm()
{
return true;
}
</script>
<body background="" bgproperties="fixed" >
<p> <FONT color=blue face=Arial size=3><strong>Update and Delete News</strong>
</FONT></P>
<?
$db=mysql_connect("localhost","","");
mysql_select_db("school",$db);
$sql="select * from news order by pdate desc";
$result=mysql_query($sql,$db);
?>
<form method="post" action="<?echo $PHP_SELF;?>"name="form" onSubmit="return CheckForm()">
<table border=1 cellspacing=0 bordercolorlight="#5e5e00" bordercolordark="#ffffec" cellpadding="2" width="560" height="12">
<tr bgcolor="#eeeee">
<td bgcolor="ccccff" height="12" width="41" align="middle"><font face="Arial, Helvetica, sans-serif" size="2"><b>Delete</b></font></td>
<td bgcolor="ccccff" height="12" width="45" align="middle"><font color="#000000" face="Arial" size="2"><b><font face="Arial, Helvetica, sans-serif">Update</font></b></font></td>
<td bgcolor="ccccff" height="12" width="70" align="middle"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">Post
Date</font></strong></font></td>
<td bgcolor="ccccff" height="12" width="70" align="middle"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">BeginOfDate</font></strong></font></td>
<td bgcolor="ccccff" height="12" width="79" align="middle"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">EndOfDate</font></strong></font></td>
<td bgcolor="ccccff" height="12" width="313"
align="middle">
<div align="center"><font color="#ffffff" face="Arial" size="2"><strong><font color="#000000">Contents</font></strong></font></div>
</td>
</tr>
<?
if (mysql_num_rows($result)>0):
while (list($id,$pdate,$bdate,$edate,$content)=mysql_fetch_row($result)):
?>
<tr>
<td height="12" width="41" valign="top">
<input type="checkbox" name="delete[]" value=http://www.phpbuilder.com/board/archive/index.php/"<?echo $id ?>">
</td>
<td height="12" width="45" valign="top">
<input type="checkbox" name="update[]" value="<?echo $id ?>">
</td>
<td height="12" width="70" valign="top">
<input type="text" name="p<?echo $id ?>"readonly value="<?echo $pdate ?>" size="10" maxlength="10">
</td>
<td height="12" width="70" valign="top">
<input type="text" name="b<?echo $id ?>"value="<?echo $bdate ?>" size="10" maxlength="10">
</td>
<td height="12" width="79" valign="top">
<input type="text" name="e<?echo $id ?>"value="<?echo $edate ?>" size="10" maxlength="10">
</td>
<td height="12" width="313" valign="top">
<textarea name="con<?echo $id ?>" COLS="50"><?echo $content ?></textarea>
</td>
<?endwhile;?>
</table>
<input type="submit" name="submit" value="submit">
</form>
<?else:?>
<font face="Arial, Helvetica, sans-serif"size="2">No any message</font>
<input type="submit" name="Submit" value="Back" onClick ="javascript:self.location.href='upnews.php'" >
<?
endif
?>
</body>
<?
}?>