now allow to change the value of variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

now allow to change the value of variable

Post by rajan »

i want to not allow the change the value of php variable when somebody refresh that page. how can this possible. i think it could be done using header but how can?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Please define PHP Variable more clearly.
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

Post by rajan »

suppose i have a varibale which will store in table when anybody refresh that page storing the variable in table will be again. how to prevent that
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

no idea what you are asking.. perhaps post some code along with a better explanation.
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

Post by rajan »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


not whole but some piece of code given below. i do not want to insert the record when somebody referesh that page

Code: Select all

<? php
if(is_null($_SESSION[count1]))
	{
		echo "hello";
		if($count>0)
		{
			if($_POST[item_name.$i]=="1 hours" ||$_POST[item_name.$i]=="2 hours" || $_POST[item_name.$i]=="5 hours")
			{
			echo "<br> item is".$item."<br> quantity is".$quant ;
			$item1="Pre-paid Support";
			}
			else
			{
		//$sql="insert into acinfo(username,accounttype,purchased,used,txnid) values('$customer_email','$item','$quant','0','$txnid')";
			$sql="update acinfo set purchased=purchased+$quant,txnid='$txnid' where username='$_SESSION[user]' and accounttype='$item'";
		//echo $sql;
		$result=mysql_query($sql) or die(mysql_error());
			}	

		}
		else
		{
		$sql="insert into acinfo values('$_SESSION[user]','$item','$quant','0','$txnid')";
		$result=mysql_query($sql) or die(mysql_error());
		echo $sql;
		}
}
	if($item1=="Pre-paid Support")
			{
			//echo "<br> item is".$item."<br> quantity is".$quant ;
			//$item1="Pre-paid Support";
			$sql="update acinfo set purchased=purchased+
			$result=mysql_query($sql) or die(mysql_error());
			}
	
}
?>

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Run a MySQL query to check if the record exists before changing it.

Something along the lines of:

Code: Select all

$sql = 'SELECT somefield FROM sometable WHERE somecondition';
$rs = mysql_query($sql);
if (mysql_num_rows($rs)) {
  //oopsy daisy, that entry already exists
}
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

Post by rajan »

i know that but i want to know how it can be done using headers.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

rajan wrote:i know that but i want to know how it can be done using headers.
Well, it bloody can't.
Post Reply