Page 1 of 1

(solved) Unknown Error

Posted: Mon Apr 04, 2005 3:06 pm
by davidjwest
I'm a newbie to PHP who has borrowed some code for a registration/login process and I get an error which I can't understand:

Code: Select all

//	if ($_POSTї'website'] != '' & !preg_match(&quote;/^(http|ftp):///&quote;, $_POSTї'//website'])) {
//		$_POSTї'website'] = 'http://'.$_POSTї'website'];
Here's the error, I'm guessing one of the slashes in the above isn't correct but not sure which one or why. I think the code takes the submitted URL and makes sure it is valid, but that's the problem with borrowing code, you never can tell unless you're not a newbie, in which case you probably code it yourself!
Warning: Unknown modifier '/' in /home/qhwslos/public_html/pitstop/register.php on line 75
Thanks for any assistance.

I should point out that I have got permission to use the code, I've not stolen it!

Posted: Mon Apr 04, 2005 3:13 pm
by s.dot
in the first line $_POST['//website'] should be $_POST['website']

Posted: Mon Apr 04, 2005 3:17 pm
by feyd
not the whole problem scrotaye...

Code: Select all

if( ($_POST['website'] != '') && !preg_match('#^(http|ftp)://#', $_POST['website']) )
{
    $_POST['website'] = 'http://' . $_POST['website'];
}
the real problem was the pattern string sent to preg_match(). You used / as a start and end pattern marker, yet you used / (without escaping it) in the pattern itself. Changing the pattern start/end markers to a different character will "fix" the problem... or if you escaped the slashes to \/ you would also be fine.

Posted: Mon Apr 04, 2005 3:18 pm
by davidjwest
Thanks but I still get the same error.

New code:

Code: Select all

if ($_POSTї'website'] != '' & !preg_match(&quote;/^(http|ftp):///&quote;, $_POSTї'website'])) {
		$_POSTї'website'] = 'http://'.$_POSTї'website'];
Should I post the whole thing? 199 lines?

Posted: Mon Apr 04, 2005 3:57 pm
by davidjwest
Now I get:
Parse error: parse error, unexpected T_VARIABLE in /home/qhwslos/public_html/pitstop/register.php on line 77

New code:

Code: Select all

if( ($_POSTї'website'] != '') && (!preg_match('#^(http|ftp)://#', $_POSTї'website']) )
    {
    $_POSTї'website'] = 'http://' . $_POSTї'website'];
	}
Line 77 is the last line above.

Posted: Mon Apr 04, 2005 4:14 pm
by feyd
oops.. sorry, I forgot another ending paren on the if line.

and please start using [syntax=php]tags.[/syntax]

Posted: Mon Apr 04, 2005 4:40 pm
by davidjwest
Thanks, it works now!

Sorry about missing off the php tags, I wondered why the colours etc were wrong, should read the "If you are going to post code of any kind, please review Posting Code in the Forums first !"

Apologies and thanks, I will know for next time!