Page 1 of 1

IF Statement not working.

Posted: Wed Jun 23, 2010 4:10 am
by aravona
I have a page which I want to pull an option from.

The page needs to have a personalised message on it, and for those pages not needing the personalised message I want the variable to display 'N/A'

The code is really long but I have this displaying on 1 page out of 6.

Code: Select all

<?php if ($_REQUEST['cid']=='49') {
			 ?>
			 <tr>
			 <td valign="middle" height="30" style="color:#7F7F7F; font-size:12px;">
			 <span style="color:#C47BBD;">&nbsp;&nbsp;Personalised Message:</span>&nbsp;&nbsp;
			 <input type="text" name="msg" value="" style="width:175px; height:16px; border:1px solid #C47BBD; color:#C47BBD; font-weight:bold;" maxlength="50"/>
			 </td>
			 <?php 
			 }
			 ?>
This works great I only get that on the one page I need it on, then once the form is submitted the following code runs:

Code: Select all

if(isset($_REQUEST['btnSubmit'])){
		
		// Begin Transaction .//
		
		
		$price = $_REQUEST['price'];
		
		$bool=false;
		$class->begin();
		
		$session_id=session_id();
		$cartDate=date("Y-m-d");
		//$totalPrice=$_REQUEST['txtTPrice'];
		$qty=$_REQUEST['qty'];
		$prID= $_REQUEST['prID'];
		$price= $_REQUEST['price'];
		
		$totalQty=$_REQUEST['qty'];
		
		if ($_REQUEST['cid']=='49') {
		$PerMes=$_REQUEST['msg'];
		}
		else {
		$PerMes = 'N/A';
		}
		
		
		$mID=$_REQUEST['mID'];
		
		$price= $_REQUEST['price'];
The problem I'm having is with the IF statement if ($_REQUEST['cid']=='49') - I'm always getting N/A rather than the custom message on this page.... On the other pages this is fine because its what I want! Any help would be appriciated!

Ara

Re: IF Statement not working.

Posted: Wed Jun 23, 2010 11:51 am
by Jade
The problem I'm having is with the IF statement if ($_REQUEST['cid']=='49') - I'm always getting N/A rather than the custom message on this page.... On the other pages this is fine because its what I want! Any help would be appriciated!
Are you setting the $_REQUEST['msg'] to something different then N/A if the $_REQUEST['cid'] = 49? Are you sure it's even getting into the if statement? It could be the cid is never getting the value of 49.

Re: IF Statement not working.

Posted: Thu Jun 24, 2010 4:55 am
by aravona
No the ID is definately 49 for that section. And since I get the private message option only on that page I know its recognising the cmd = 49 elsewhere.

Re: IF Statement not working.

Posted: Tue Jun 29, 2010 6:33 pm
by Jade
Are you passing the cid again when you post the form? The cid won't be carried over to another page if it's not in the form action query string or in the data that's being posted back to the server. Either your form action needs to be changed to include the cid or you need to post the cid as a hidden field. The only time variables are carried over from one page to another is if you're using cookies or sessions. Otherwise the data in the $_REQUEST field is cleared out/repopulated with each page change.

Code: Select all

<form action="?cid=<?php echo $_REQUEST['cid']; ?>" method="post">
OR include it as a hidden field

Code: Select all

<input type="hidden" name="cid" value="<?php echo $_REQUEST['cid']; ?>" />