IF Statement not working.

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
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

IF Statement not working.

Post 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
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: IF Statement not working.

Post 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.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: IF Statement not working.

Post 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.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: IF Statement not working.

Post 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']; ?>" />
Post Reply