(solved) Unknown Error

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
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

(solved) Unknown Error

Post 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!
Last edited by davidjwest on Wed Apr 06, 2005 10:35 pm, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

in the first line $_POST['//website'] should be $_POST['website']
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Last edited by feyd on Mon Apr 04, 2005 4:46 pm, edited 2 times in total.
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

Post 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?
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

oops.. sorry, I forgot another ending paren on the if line.

and please start using [syntax=php]tags.[/syntax]
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

Post 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!
Post Reply