Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts

    if Statement causing an error

    I get this error

    unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

    which points to the if statement shown in the code below. I copied the lines below also. I am getting this straight from a book so I don't see what is wrong with it. I have tried commenting out other lines thinking it may actually be somewhere else that throws the error, but no good.
    Code:
    if (isset($_POST['submit'])) {  
    	//from has been submitted
    	if(ini_get('magic_quotes_gpc')) { //see if magic quotes are turned on
    		$pattern=stripslashes($_POST['pattern']);
    		$string=stripslashes($_POST['string']);
    	}else{
    		$pattern=$_POST['pattern'];
    		$string=$_POST['string'];
    	}
    	$pattern=trim('$pattern');
    	$string=trim('string');
    }else{ //form has not been submitted
    	$pattern='';
    	$string='';
    }
    Scott Stewart
    Always happy to learn from pros.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    That particular piece of code by it self does not generate an error. Post at least 20 lines of code prior to that. Also, use the php code tags (the little folded corner paper icon with "php" on it) around the code in your post to get the highlighting to help find things like mis-matched quotes. Posting the line number part of the error message and indicating which line in the posted code that refers to would also help.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    NEVER MIND! It was there and I couldn't see it. Literally! My contacts suck. Instead of a tilde in the error handling I had a single quote `
    Code:
    error_reporting(E_ALL & `E_NOTICE);
    This line was just prior to the if.

    None of this matters now except as an example of stupid errors.
    New rule. Forget the contacts use cheesy reading glasses when working on my computer.
    Scott Stewart
    Always happy to learn from pros.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •