Page 1 of 1

Newbie stumped by echo()

Posted: Fri Jun 27, 2003 1:17 pm
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.

Posted: Fri Jun 27, 2003 1:36 pm
by jason
It works fine.

I have a feeling you aren't giving us all the code, though.

Posted: Fri Jun 27, 2003 1:37 pm
by jason
Sorry, also, could you copy/paste the Parse error you are getting with the source code.

Posted: Fri Jun 27, 2003 3:17 pm
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

gremlins

Posted: Fri Jun 27, 2003 3:49 pm
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.
:?

Posted: Fri Jun 27, 2003 3:55 pm
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

Posted: Fri Jun 27, 2003 4:00 pm
by JPlush76
psshhh you call them gremlins? I call them sys admins ;)

Re: gremlins

Posted: Fri Jun 27, 2003 5:32 pm
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?

Posted: Sat Jun 28, 2003 3:39 am
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.