Newbie stumped by echo()

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
paraparker
Forum Newbie
Posts: 3
Joined: Fri Jun 27, 2003 1:17 pm

Newbie stumped by echo()

Post by paraparker »

New to this sorry, but I'm wondering why this will work:

Code: Select all

<?php
while($query_result=mysql_fetch_array($query)) {
	
	$qvar = $query_result["address"];
$id = $query_result["id"];

 if (eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $qvar)) {
 	
 	echo "Syntax is good:  $qvar <br>";
 	
 	}
}
?>
And this gives me a parse error on the echo line:

Code: Select all

<?php
while($query_result=mysql_fetch_array($query)) {
	
	$qvar = $query_result["address"];
$id = $query_result["id"];

if (eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $qvar)) {
 
        echo "Syntax is good:  $qvar <br>";
		mysql_query("update temp set syntax='y',valid='n',already_checked='y' where id='$id'");
		$syn = "g";
    }
}
?>
Honestly, I'm stumped. I checked the query with a shell and it works fine, setting $syn should be fine. Using PHP 4.1.2. Thanks for the newbie patience as I'm sure this is obvious to most. :oops:

Admin Edit: Please use the PHP BBCode tags. It helps bring about world peace.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

It works fine.

I have a feeling you aren't giving us all the code, though.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Sorry, also, could you copy/paste the Parse error you are getting with the source code.
paraparker
Forum Newbie
Posts: 3
Joined: Fri Jun 27, 2003 1:17 pm

Post by paraparker »

Thanks for offering to help! I know it's something small like a ' or a ), but I'm not seeing it. :cry:

Here is the whole file:

Code: Select all

<? 

// Connect to the MySQL database

$host = "localhost";
$sql_user = "blah";
$sql_pwd = "blah";
$db = "validate_email";
mysql_pconnect("$host","$sql_user","$sql_pwd");
mysql_select_db("$db");

// Query the database and setup a loop. Grab an email and process the sucker.

$query=mysql_query("select * from temp");

while($query_result=mysql_fetch_array($query)) {
	
	$qvar = $query_result["address"];
	$id = $query_result["id"];

	 if (eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $qvar)) {
        
		echo "Syntax is good:  $qvar <br>";
		
		mysql_query("update temp set syntax='y',valid='n',already_checked='y' where id='$id'");
		
		echo "Checking email validity now...<br>";
		
		// Explode out the domain name for the user so we can connect to the MX server (if any)
		// for that domain and see if this user even exists when we telnet in.

		list ($user, $domain) = split ("@",  strtolower($qvar), 2);

			// Try to telnet to mail server and say hi and send some stuff to confirm account!
			
			$c_smtp = fsockopen ($domain, 25); 
        	
			if (ereg ("^220", $out=fgets($c_smtp ,1024))) {

             fputs ($c_smtp ,"HELO $HTTP_HOST \r\n ");
             $out = fgets ($c_smtp ,1024 );
             fputs ($c_smtp ,"MAIL FROM: <validate_email@blah.com>\r\n "); 
             $from = fgets ($c_smtp ,1024 );
             fputs ($c_smtp ,"RCPT TO: <$qvar>\r\n ");         
             $to =fgets ($c_smtp ,1024 );
             fputs ($c_smtp ,"QUIT\r\n" ); 
             fclose ($c_smtp); 

            	if (! ereg ("^250" ,$to )) { 

					// On no RCPT TO hello we break the loop.
			
					echo "Looks like an invalid user.<br>";
					mysql_query("update temp set syntax='y', valid='n', already_checked='y' where id='$id'");	
                }
				else {
				
					// Otherwise we have a winner!
					
					echo "Valid user!<br><br>";
				 	mysql_query("update temp set syntax='y', valid='y', already_checked='y' where id='$id'");
				}
			}
			else {
			
				echo "Couldn't connect to the mail server.. moving on.";
				mysql_query("update temp set syntax='y', valid='n', already_checked='y' where id='$id'");
			}
		}
		
		else {
				echo "Syntax is bad:  $qvar <br>";
				mysql_query("update temp set syntax='n',valid='n',already_checked='y' where id='$id'");
			}
	}
?>
Error is:

Parse error: parse error in /path/validate_emails.php on line 23
paraparker
Forum Newbie
Posts: 3
Joined: Fri Jun 27, 2003 1:17 pm

gremlins

Post by paraparker »

OKay hang tight.. I made a little test page:

Code: Select all

<?         

$foo = "Bar";
echo $foo;

?>
That didn't work, gave me a parse error, and that lead me to whitespace, line breaks etc. I got rid of all whitespace and it worked.. will look at the other code for invisible gremlins.
:?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

I remember a while ago someone had problems with their script and it seemed like spaces had been converted to something else - when all the whitespace was replaced with actual spaces it worked. Gremlins can do some weird stuff at times.

Mac
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

psshhh you call them gremlins? I call them sys admins ;)
User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Re: gremlins

Post by HungryMind »

paraparker wrote:That didn't work, gave me a parse error, and that lead me to whitespace, line breaks etc. I got rid of all whitespace and it worked.. will look at the other code for invisible gremlins.
:?
This is very strange. Are you using notepad? What browser are you viewing your code with. Whitespace shouldn't make too much of a difference, unless you start putting it in between words and in the middle of a variable. For example:

Code: Select all

<?

  $foo   =                "Bar"   ;
     echo     $foo  ;

    ?>
Works just fine for me, the output being: "Bar". Maybe you should look into changing either your browser or your text program?
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

As far as I know, it's also possible that your text editor and server aren't running on the same operating system. Windows and *NIX have different linebreaks (a combination of "\r" and "\n"), so it's possible that php is parsing some form of linebreak as a character.
Post Reply