Intermittent increments..or not

Hi all, I have some code which is used for storing information in the form of questions and answers…there are what seems to be intermittent results…seems ok when i am logged in but not so good when others…(however this doesn’t seem true in all cases)

I will keep it simple as to where I think the problem may be and omit code I think isn’t relative…please correct me if im wrong…this is the flow as see it :

  1. When user clicks the link to start the questions the page sheet_question.php is loaded with the following code included near the top of the file script

My understanding is that this will remove any entries from the 3 tables if the user clicks ‘cancel as in step 5 below
[php]
if($_GET[‘post_no’]!=’’){
$Del=“delete from post_count where post_no=’$_GET[post_no]’”;
$rs=MySQLQuery($Del);

$Del=“delete from draft_letter where post_no=’$_GET[post_no]’”;
$rs=MySQLQuery($Del);

$Del=“delete from appeal_letter where post_no=’$_GET[post_no]’”;
$rs=MySQLQuery($Del);

}

[/php]

  1. The same page includes some javascript near the bottom that calls the file get_option.php which includes the following code:

When the user starts the questions and sheet_questions.php loads then $_GET[‘id’] does = 2 and $_SESSION[‘EXITCODEPAGE’] does =’’

If it’s the first time a user has logged in to aswer questions there is no entry for the user in post_count table

What should happen is that the post_count table should increment by 1 each time the user goes through this cycle. The value inserted into post_count should be filtered down and inserted into draft_letter.php (point 3) and appeal_letter.php (point 4)

As explained this increment seems to happen for me ok but when i check the entry for another user in post_count it is either has the value ‘1’ or it is non existent (even though they have answered questions through to point 6)

Also im not sure of the relevance of the code at the bottom (after the insert code)

[php]
if($_GET[‘id’]==2 && $_SESSION[‘EXITCODEPAGE’]==’’){

 $sl="select * from post_count where user_id='".$_SESSION['user_id']."' order by id DESC limit 0,1";

 $or=MySQLQuery($sl);

 $rws=mysql_fetch_array($or);

 $rws['post_no'];

 $rws['post_no']=$rws['post_no']+1;

 $post_no=$rws['post_no'];

 $swl="insert into post_count



		set

			user_id		=	'$_SESSION[user_id]',

			entery_date	=	'".date("Y-m-d")."',

			post_no		=	'$rws[post_no]'";

		

		MySQLQuery($swl);

}



if( $rws['post_no']==''){



 $sll="select * from post_count where user_id='".$_SESSION['user_id']."' order by id DESC limit 0,1";

 $orr=MySQLQuery($sll);

 $rwss=mysql_fetch_array($orr);

 $post_no = $rwss['post_no'];

 

}

[/php]

  1. Further down the same file the following code is included to insert into table draft_letter.php

[php]
$ssq="insert into draft_letter

			set

				user_id		=	'".$_SESSION['user_id']."',

				question	=	'".$question."',				
				
				no_appeal_text	=	'".$no_appeal."',";		

	if(isset($_GET['text_box']) && $_GET['text_box']!='undefined'){

		

	$ssq .=	"answer		=	'".$textBox."',";

		}

		elseif($_GET['time1']!='' && $_GET['time1']!=': '){			

	$ssq .=	"answer		=	'".$_GET['time1']."',";

		}

		elseif($_GET['time2']!='' && $_GET['time2']!=': '){			

	$ssq .=	"answer		=	'".$_GET['time2'].' to '.$_GET['time3']."',";

		}

		elseif($rows['input_type']=='Time Input & Radiobutton' && $_GET['time1']=='' && $_GET['time2']=='' && $_GET['time3']==''){			

	$ssq .=	"answer		=	'There is no time',";

		}

		else{			

	$ssq .=	"answer		=	'".$ans."',";

		}

		$ssq .=	"field_id	=	'".$rows['id']."',

				post_no		=	'$post_no'";
				
				
				
	
		MySQLQuery($ssq);

[/php]

  1. and also further down to insert into appeal_letter.php

[php]

$ssq="insert into appeal_letter

			set

				user_id		=	'".$_SESSION['user_id']."',

				appeal_text	=	'".addslashes($rrr)."',";

if($row[‘LASTPAGEINFO’]!=’’){

	$ssq.=  "LASTPAGEINFO	=	'".addslashes($row['LASTPAGEINFO'])."',";

}



		$ssq.=  "field_id	=	'".$rows['id']."',

				post_no		=	'$post_no'";

		

		MySQLQuery($ssq);

[/php]

  1. If the user goes through the questions and then decides to start over by clicking ‘cancel’ they then cycle round to the beginning (point 1) with the code below

[php]

[/php]

  1. When user has completed answering questions and clicks ‘finish’ the data is sent through to another page as below

[php]

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service