Einfache PLZ-Suche mit MySQL geht nicht!

Vielleicht hast du mich falsch verstanden.

PHP:
<form action="" method="post">
<span> PLZ eingeben </span><input type="text" name="PLZ_form" maxlenght="5" />
<input type="submit" value="Suchen" />
</form>

<?php

	if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
		//SQL Connect
		$provider = "page.de";
		$dbuser = "U******";
		$dbpass = "**********";
		$dbname = "D******";

		$db_connect = mysql_connect($provider, $dbuser, $dbpass)
			or die("Connection Failure to Database");

		mysql_select_db($dbname, $db_connect)
			or die($dbname . " Database not found." . $dbuser);

		//Formulerdaten in "$form" speichern
		$form = isset($_POST['PLZ_form']) ? $_POST['PLZ_form'] : '';

		//SQL abfrage
		$query = "SELECT * From stellen WHERE PLZ = '".mysql_real_escape_string($form)."' ";
		if( ($result = mysql_query($query) === false ) {
			echo mysql_error();
		} else {
			while( $row = mysql_fetch_array($result) ) {
				//Händler und Ort ausgeben
				echo $row['haendler']." in ".$row['ort'];
				if( $row['PLZ'] == "" ) {
					echo "none";
				}
			}
		}
	}

?>
 
Zurück