我有一個代碼將數據插入到數據庫中,並且在數據成功插入到數據庫後,用戶需要刷新頁面以查看最近插入的數據的標題。所以我的問題是,當我刷新頁面的數據有重複,請你糾正我的代碼:停止重新提交頁面時刷新數據,php
<!DOCTYPE html5>
<html>
<head><title>Admin Page Penuel Construction</title> <link rel='stylesheet' type='text/css' href='AdminCss.css'/>
<meta name='description' content='Laboratory Activity 10'>
<meta name='keywords' content='HTML,CSS,JavaScript,PHP'>
<meta name='author' content='Monterde, Krystine Ann Marie'>
<meta charset='UTF-8'>
<script src="validation.js" type="text/javascript" ></script>
</head>
<body id='main_background'>
<center>
<div id='container'>
<div id='header'> </div>
<div id='mainContent'>
<div id='leftContent'>
<div id='greeting_box'><p id='greeting_style'>HELLO ADMIN!</p></div>
<div id='sidenav_title'><div class='sidenav_style_title color_nav_background_one' >Penuel Construction</div>
<table class='table_division_nav'>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><a href='BuildingBlocks_Penuel_News_Unpublished.html' class='style_text_nav' >News/Updates</a></td></tr>
<tr><td><a href='BuildingBlocks_Penuel_Projects_Ongoing.html' class='style_text_nav' >Projects</a></td></tr>
<tr><td><a href='BuildingBlocks_Penuel_About_Us.html' class='style_text_nav' >About Us</a></td></tr>
</table></div>
<div id='sidenav_title_two'><div class='sidenav_style_title color_nav_background_two'>Samantha's Place</div>
<table class='table_division_nav'>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><a href='BuildingBlocks_Samantha_News_Unpublished.html' class='style_text_nav' >News/Updates</a></td></tr>
<tr><td><a href='BuildingBlocks_Samantha1.html' class='style_text_nav' >Projects</a></td></tr>
<tr><td><a href='BuildingBlocks_Samantha_Promos_Unpublished.html' class='style_text_nav' >Promos</a></td></tr>
</table></div>
<div id='sidenav_title'><div class='sidenav_style_title color_nav_background_three'>Others</div>
<table class='table_division_nav'>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><a href='BuildingBlocks_Others.html' class='style_text_nav' >Contact Us</a></td></tr>
<tr><td><a href='#' class='style_text_nav' >Log Out</a></td></tr>
</table></div>
</div>
<?php
//getting data from database
include('connect_to_db.php');
$querys="SELECT * FROM pc_news";
$result=mysql_query($querys);
$num=mysql_numrows($result);
mysql_close($link);
?>
<div class='color_nav_background_one' id='rightcontent'>
<div id='right_content_upper'>
<div class='projects_navigation_news'><a href='BuildingBlocks_Penuel_News_Unpublished.html' >Unpublished</a></div><div class='projects_navigation_news'> <a href='BuildingBlocks_Penuel_News_Published.html'>Published</a></div>
<div id='divsion_under_news_navigation_Unpublished'></div>
<table id='table_sytle'>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<?php
//viewing data from database
$i=0;
while ($i < $num)
{
$title=mysql_result($result,$i,"title");
?>
<tr>
<?php print"<td><p class='rightcontent_upper_text_sytle'> $title </p></td><td></td><td onclick><a href='####' class='action_textstyle_table'id='color_action_edit'>Edit</a></td><td onclick><a href='#' class='action_textstyle_table' id='color_action_delete'>Delete</a></td><td onclick><a href='#' class='action_textstyle_table' id='color_action_complete_or_published'>Published</a></td></tr> "; ?>
</tr>
<?php $i++;} ?>
</table>
<div class='postion_paging'>1-5/150</div>
<div id='postion_select'><input type='button' value='<<Prev' class='button_style'><input type='button' value='Next>>' class='button_style'></div>
</div>
<div id='right_content_lower_left'>
<form name = "unpublished_check" onsubmit = "return unpublishedCheck()" action="sampleNewscode.php" method ="post" enctype = "multipart/form-data">
<table >
<tr><td> Choose Status: </td>
<td><input name="status" type='radio' value='0' />Unpublished<input name="status" type='radio' value='1'/>Published</td></tr>
<tr><td><p class='rightcontent_lower_left_text_sytle'>Title:</p></td><td><input type='text' id='textbox_style' name = 'title'/></td></tr>
<tr><td> Attach Image/s:</td>
<td><input type='file' name='photo' accept="image/*" /> <input type = 'hidden' name = 'MAX_FILE_SIZE' value = '5000000'></td></tr>
<tr><td><p class='rightcontent_lower_left_text_sytle'>Content:</p></td>
<td><textarea rows='7' cols='70' name = 'txtarea'></textarea></td></tr>
<tr><td><input type='submit' name='submit' value='Submit'/></td></tr>
</table>
</form>
</div>
</div>
</div>
<div id='footer'></div>
</div>
</center>
<?php
//inserting data unto database
if(isset($_POST['submit']))
{
include('connect_to_db.php');
$status = $_POST['status'];
$dir = "images/";
$tmp_name = $_FILES['photo']['tmp_name'];
$pic = $_FILES['photo']['name'];
$title = mysql_real_escape_string ($_POST['title']);
$txtarea = mysql_real_escape_string ($_POST['txtarea']);
if(move_uploaded_file($tmp_name, $dir . $pic)){
$query = "INSERT INTO pc_news VALUES('$title','$txtarea','$pic','$status')";
mysql_query($query) or die(mysql_error());
}
else{
echo "Sorry, there was a problem uploading your file.";
}
mysql_close($link);
}
?>
</body>
</html>
有一個在一個問題與您的名字完全相同的權利----------------------------------------- ----------------> –
爲什麼不偶爾搜索一個答案,而不是詢問?只是爲了改變? –
可能重複[如何停止頁面重新刷新頁面?](http://stackoverflow.com/questions/15081323/how-to-stop-resubmitting-of-page-on-refreshing-the-page) –