Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with php script

Status
Not open for further replies.

HaaDeej

Technical User
Feb 3, 2005
7
NL
I have this script. It's a postcode check script, 8911 is now a correct code, but I have to add a few, i've tried everything but i'm not a genious in PHP, maybe someone could help me out. The postcode's that the script has to find "correct" are: 8911 (it's already in the script), 8912, 8913, 8914, 8915, 8916, 8917, 8918, 8919, 8921, 8922, 8923, 8924, 8925, 8926, 8931, 8932, 8933, 8934, 8935, 8936, 8937, 8939, 9084.

All the other code's have to be incorrect!


<?php
// postcode check
if($submit){


$patroon = "^([8911]{4}) ([A-Z]{2})$";
if(eregi($patroon, $pc)) {
echo "Postcode is correct";
}

else {
echo "Postcode is not correct";
}

}
else {
?>

<form method=post>
Postcode (8900 AB): <input type='text' name=pc><BR>
<input type=submit name=submit value=check!>
</form>
<?
}
?>
 
Why make yourself crazy over regular expressions?

Code:
<?php 
$postcodes = array (8911, 8912, 8913, 8914, 8915, 8916, 8917, 8918, 8919, 8921, 8922, 8923, 8924, 8925, 8926, 8931, 8932, 8933, 8934, 8935, 8936, 8937, 8939, 9084)

// postcode check 
if($submit)
{ 
	if(in_array ($pc, $postcodes))
	{ 
		echo "Postcode is correct"; 
	} 

else
.
.
.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
<?php
$postcodes = array (8911, 8912, 8913, 8914, 8915, 8916, 8917, 8918, 8919, 8921, 8922, 8923, 8924, 8925, 8926, 8931, 8932, 8933, 8934, 8935, 8936, 8937, 8939, 9084)

// postcode check
if($submit)
{
if(in_array ($pc, $postcodes))
echo "Postcode is correct";
}

else {
echo "Postcode is not correct";
}

}
else {
?>

<form method=post>
Postcode (8900 AB): <input type='text' name=pc><BR>
<input type=submit name=submit value=check!>
</form>
<?
}
?>



If I use this, I'll get:

Parse error: parse error, unexpected T_IF in /data/members/paid/h/a/haadeej.nl/htdocs/pizzeria/postcode.php on line 5
 
What I posted wasn't working code.

This:

Code:
$postcodes = array (8911, 8912, 8913, 8914, 8915, 8916, 8917, 8918, 8919, 8921, 8922, 8923, 8924, 8925, 8926, 8931, 8932, 8933, 8934, 8935, 8936, 8937, 8939, 9084)

should read

Code:
$postcodes = array (8911, 8912, 8913, 8914, 8915, 8916, 8917, 8918, 8919, 8921, 8922, 8923, 8924, 8925, 8926, 8931, 8932, 8933, 8934, 8935, 8936, 8937, 8939, 9084)[red];[/red]

There's a missing semicolon at the end of the line.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Could you post the whole code for me?
Then I won't make mistakes anymore! :)
Because with the ; it still doesn't works.
I get the same error again!
 
Forget it, IT WORKS :)
Thank you VERY much!
You're the man! ;)
 
Is it possible to redirect in stead of: echo "Postcode correct";
 
Yes, it is possible. However, if your script is going to set an HTTP header, your script must not have produced any output before the header is set.

See faq434-2999


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I don't understand it.. can you make an example for me? :$
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top