have a real problem.
i have a php page that deletes all records in a table if the page is loading for the first time-mysql_query("delete from table") and inserts a new record if not. the problem i have is that whenever the page reloads, the records of the table are deleted again. i know the 'if' block that i use to check if the page was loading for the first time is not running again cos theres a print statement in d if block that tells me if the block is executed. i know that a new record is being inserted cos immediately after insertion, i count the number of records in d table and its increased by one but whenever the page reloads, th number of records returns to zero. can anyone help. heres wat d code looks like:
<?php
include('incs/dbcon.inc');
if(!empty($_POST['first'])) $first=$_POST['first'];
print "hasbeen inserted and number in table now is ".mysql_num_rows(mysql_query("select * from real_time"));
//check if this is beginning of test. if it is it gets d subject and test year from the previous page(past-questions-subjects-govt.html)
if($first!="no") {
print "gimmie something to work on man ";
$dq=mysql_query("delete from real_time") or die(mysql_error());
}
print "hasbeen inserted and number in table now is ".mysql_num_rows(mysql_query("select * from real_time"));
mysql_query("insert into real_time values('','$qtn_id','$ans','$model_ans','$qtn_num')") or die(mysql_error());
print "hasbeen inserted and number in table now is ".mysql_num_rows(mysql_query("select * from real_time"));
++$qtn_num;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JAMB Virtual Tutorial College | Test Center</title>
<style type="text/css">
<!--
body {
background-image: url(file:///X|/Projects/Go Virtual Solutions/OCEANIC VLA/images/bg.jpg);
background-repeat: repeat-x;
background-image: url(file:///X|/Projects/Go Virtual Solutions/OCEANIC VLA/images/bg.jpg);
background-image: url(file:///X|/Projects/Go Virtual Solutions/OCEANIC VLA/images/bg.jpg);
background-color: #0C400F;
background-image: url();
}
.style2 {
font-family: Calibri;
font-size: 12px;
}
-->
</style>
<style type="text/css">
<!--
a:link {
color: #3280A4;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #3280A4;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
.style49 {color: #FFFFFF}
.style50 {font-size: 13px}
.style51 {color: #A4812F}
.style52 {
font-size: 24px;
font-family: Calibri;
font-weight: bold;
color: #1B143D;
}
.style74 { font-family:Calibri; font-size: 12px; color: #000000; }
-->
</style>
<script language="javascript" type="text/javascript">
var d=new Date();
var monthName= new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var today= monthName[d.getMonth()]+" "+d.getDate()+" "+d.getFullYear();
</script>
<script language="javascript">
function goBack(real_time_id,qtn_num,dept_id,ans)
{
location.assign("testcenter-qtns.php?prev_real_time_id="+real_time_id+"&qtn_num="+qtn_num+"&dept_id="+dept_id+"&ans="+ans+"&rtid=yep");
}
</script>
</head>
<body topmargin="0">
<table width="751" border="0" align="center" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="567" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr>
<td height="134" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="751" height="134" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/testcenter-banner.jpg">
<!--DWLayoutTable-->
<tr>
<td width="233" height="64"> </td>
<td width="114"> </td>
<td width="404" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="43"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="27"> </td>
<td colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="91" height="2"></td>
<td width="427"></td>
</tr>
<tr>
<td height="14"></td>
<td valign="top" class="style2"></td>
</tr>
<tr>
<td height="11"></td>
<td></td>
</tr>
</table> </td>
</tr>
</table></td>
</tr>
</table> </td>
</tr>
<tr>
<td height="53" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0">
<!--DWLayoutTable-->
<tr>
<td width="542" height="53" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="75"></td>
<td width="170" height="14"></td>
<td width="44"></td>
<td colspan="2" valign="middle"><strong class="style2">Name of Subject: </strong> <strong class="style2 style51"><?php echo $subject;?></strong></td>
<td width="49"></td>
</tr>
<tr>
<td></td>
<td height="7"></td>
<td></td>
<td width="160"></td>
<td width="44"></td>
<td></td>
</tr>
<tr>
<td></td>
<td height="4"></td>
<td></td>
<td rowspan="2" valign="top"><strong class="style2">Duration of Test:</strong> <strong class="style2 style51">20mins</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td height="15" valign="top"><span class="style2 style50"><strong>Date: </strong><strong class="style2 style51"><script language="javascript">document.write(today);</script>
</strong></span></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td height="13"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table></td>
<td width="208" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="208" height="15" valign="top"><strong class="style2">No. of Questions:</strong> <strong class="style2 style51"><?php echo $numQ;?> </strong></td>
</tr>
<tr>
<td height="6"></td>
</tr>
<tr>
<td height="14" valign="top"><strong class="style2">Total Score:</strong> <strong class="style2 style51"><?php echo $numQ;?> </strong></td>
</tr>
<tr>
<td height="5"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td width="64" height="5"></td>
<td width="629"></td>
<td width="58"></td>
</tr>
<tr>
<td height="29" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="60" height="29" valign="top" class="style52"><div align="center"></div></td>
<td width="689" valign="top" class="style52"><div align="left"><?php echo $subject;?> | <?php echo $test_year;?></div></td>
</tr>
</table></td>
</tr>
<tr>
<td height="29"> </td>
<td></td>
<td></td>
</tr>
<tr>
<td height="305"> </td>
<td valign="top" class="style74">
</td>
<td> </td>
</tr>
<tr>
<td height="17"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table></td>
</tr>
<tr>
<td width="95" height="14"></td>
<td width="585" valign="top"><div align="center"><span class="style2 style49"> <a href="index.html">Home</a> | <a href="Library.html">Library </a>| <a href="past-questions.html">Past Questions</a> | <a href="past-questions-subjects-govt.html">Past Questions in govt</a> | <a href="tutorial center.html">Tutorial Center </a>| Help </span></div></td>
<td width="71"></td>
</tr>
</table>
</body>
</html>
recurring delete
Moderator: General Moderators
-
WebbieDave
- Forum Contributor
- Posts: 213
- Joined: Sun Jul 15, 2007 7:07 am
Re: recurring delete
Can you repost your code with php tags? It makes the code more readable. Check out the posting guidelines for more info.
Re: recurring delete
Just go back to your post, Edit it and enclose your code between [syntax=php]and[/syntax] tags.
Re: recurring delete
Try storing your count variable in session and implement the check using that. This will give you the desired results.