Felder auf eingabe prüfen

Madej

Mitglied
PHP:
<?PHP
include ("checkuser.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test</title>
<link rel="SHORTCUT ICON" href="icon.ico">
<link rel="SHORTCUT ICON" href="Logo_kleiner.jpg">
</head>
<body bgcolor="white" text="#990000" link="#0000CC" vlink="#000066" alink="#000000">
<h2 align="center">Neuen Eintrag erstellen</h2>
<form action="erstellen.php" method="post">
<table align="center" border="1" cellpadding="1" cellspacing="0">
	<tr>
	<th><font color="red">*</font>Titel:</th>
	<td><input type="text" name="titel" ></td>
	</tr>
<tr>
	<th><font color="red">*</font>Sparte:</th>
	<td>
	<select name="sparte">
	<option>medien</option>
	<option>Eis</option>
	<option>Sahne</option>
	<option>Eier</option>
	</select>
	</td>
</tr>		
	<tr>
		<th><font color="red">*</font>Adresse:</th>
		<td><input type="text" name="adresse"></td>
	</tr>
	<tr>
		<th><font color="red">*</font>HausNr.:</th>
		<td><input type="text" name="hausnr"></td>
	</tr>
	<tr>
		<th><font color="red">*</font>projekt.:</th>
		<td><input type="text" name="projekt"></td>
	</tr>
	<tr>
		<th><font color="red">*</font>Anfrage von:</th>
		<td><input type="text" name="anfragevon"></td>
	</tr>
	<tr>
		<th><font color="red">*</font>Verwantes Problem:</th>
		<td><input type="text" name="verwantesproblem"></td>
	</tr>
<tr>
	<th><font color="red">*</font>Priorität:</th>
	<td>
	<select name="prioriteat">
	<option>hoch</option>
	<option>normal</option>
	<option>niedrig</option>
	</select>
	</td>
</tr>	
	<tr>
		<th><font color="red">*</font>Kommentar.:</th>
		<td><textarea name="kommentar" cols="50" rows="10"></textarea></td>
	</tr>
	<tr>
		<th>Anhang:</th>
		<td><input type="file" name="anhang1"><br>
		<input type="file" name="anhang2"><br>
		<input type="file" name="anhang3"><br>
		<input type="file" name="anhang4"><br>
		<input type="file" name="anhang5"><br>
		<input type="file" name="anhang6"><br>
		<input type="file" name="anhang7"><br>
		<input type="file" name="anhang8"></td>
	</tr>
	<tr>
		<td><font color="red">* Pflichtfelder</font></td>
		<td align="right"><input type="submit" name="erstellen" value="Erstellen"></td>
	</tr>
</table>
</form>
</body>
</html>

Funktion:
Man dies Felder aus und die werden dann in eine Datenbank geschrieben.
Problem:
Bevor etwas in die Datenbank geschrieben wird, soll Überprüft werden ob die Felder ausgefüllt worden sind. Wie kann ich des gut lösen, aber nur mit php.

Gruß
 
PHP:
if(isset($_POST['titel']) && !empty($titel));
		else 	{
			echo "<font color='red'>Füllen Sie bitte das Feld 'Titel' aus!</font> <br/>";
				}
Gibt es keine andere Lösung?
 
Fall es jemanden interssiert, ich hab des jetzt auf die art geöst:

PHP:
<?php  
$error = NULL;  
function GET_POST_VAR($index=false)	
	{
	if(!empty($index)) 
		{
		if(isset($_POST[$index]) && !empty($_POST[$index]) && $_POST[$index]!="") 
			{
			return $_POST[$index];
			} 
				else 
			{
				return false;
			}
	    } 
				else 
			{
	    		return false;
	        }
	}											
?>
<HTML>
<HEAD>
<TITLE>Anmeldung</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
  <?php  $submit = GET_POST_VAR("submit");
  $name = GET_POST_VAR("name");
  $mail = GET_POST_VAR("mail");
  $semester = GET_POST_VAR("semester");
  if($submit != false) {
  if($name === false) $error['name'] = "Es wurde keine Name angegeben.";
	if($mail === false) $error['mail'] = "Es wurde kein email-Adresse angegeben.";
	if($semester === false) $error['semester'] = "Es wurde kein Semester angegeben.";
	if(is_array($error)) {
	$submit = false;
	} else {
	$submit = true;
	} 
   }
  	                      if($submit != false) {
  	                      	echo("Anmeldung erfolgreich");
  	                        } else 
  	                        {
  	                        ?>
  	                        <h1 align="center">Anmeldeformular</h1><br>
  	                        <FORM ACTION="lol.php" METHOD="POST">
  	                        Name:<INPUT TYPE="text" name="name" value="<?php if(!empty($name)) echo($name);?>">
  	                        <?php 
  	                        if(isset($error['name'])) 
  	                        echo("<span style=\"color:red\">".$error['name']."</span>");?>
  	                        <p>eMail:<INPUT TYPE="text" name="mail" value="<?php if(!empty($mail)) echo($mail); ?>">
  	                        <?php if(isset($error['mail'])) echo("<span style=\"color:red\">".$error['mail']."</span>");?>
  	                        <p>Semester:<INPUT TYPE="text" name="semester" value="<?php if(!empty($semester)) echo($semester); ?>">
  	                        <?php if(isset($error['semester'])) echo("<span style=\"color:red\">".$error['semester']."</span>");?>
  	                        <p><p><INPUT TYPE="submit" value="Anmelden" name="submit"></p>
  	                        </FORM>
  	                        <?php 
  	                         }
  	                         ?>
  	                         </BODY>
  	                         </HTML>
 

Neue Beiträge

Zurück