und der andere Code
<?php
#Verbindung zur Datenbank
define('HOST','localhost');
define('USER','user');
define('PASS','pass');
define('DB','oppeloppa');
mysql_connect(HOST,USER,PASS);
mysql_select_db(DB);
#Anzahl der Blitze ermitteln
$sql = "SELECT id,user FROM blitz";
$blitz_query = mysql_query($sql) or die("Anfrage nicht erfolgreich");
$anzahl = mysql_num_rows($blitz_query);
#Der Text dazu
echo "Bisher sind $anzahl Opel Blitz eingetragen <BR> \n";
echo "Bitte unbedingt das Baujahr als 4 stellige Zahl angeben (Bsp.: 1966) <BR> \n";
echo "Sonst funktioniert das Sortieren im User-Blitz nicht richtig <BR> \n";
echo "Vertippt? Daten sollen geändert oder gelöscht werden? <BR> \n";
echo " Mail an info@opel-blitzschmie.de, da werden sie geholfen <BR> \n";
#Das Eingabeformular
echo '<form name="upload" action="" method="POST" enctype="multipart/form-data">';
echo '<table>';
echo '<tr><th>User:</th><td><input name="user" type="text"></td></tr>';
echo '<tr><th>Model:</th><td><input name="model" type="text"></td></tr>';
echo '<tr><th>Baujahr:</th><td><input name="jahr" type="text"></td></tr>';
echo '<tr><th>Aufbau:</th><td><input name="aufbau" type="text"></td></tr>';
echo '<tr><th>Motor:</th><td><input name="motor" type="text"></td></tr>';
echo '<tr><th>PS:</th><td><input name="ps" type="text"></td></tr>';
echo '<tr><th>Hubraum:</th><td><input name="hubraum" type="text"></td></tr>';
echo '<tr><th>Sonstiges:</th><td><input name="sonstiges" type="text"></td></tr>';
echo '<tr><th>Beschreibung:</th><td><textarea name="beschreibung"></textarea></td></tr>';
echo '<tr><th>Foto:</th><td><input type="file" name="foto"></td></tr>';
echo '<tr><th><input type="submit" name="upload" value="Hinzufügen"></th></tr>';
echo '</table>';
echo '</form>';
function cl($input){return mysql_real_escape_string($input);
}
if(isset($_POST['upload'])){$_POST['user'] = cl($_POST['user']);
$_POST['model'] = cl($_POST['model']);
$_POST['jahr'] = cl($_POST['jahr']);
$_POST['aufbau'] = cl($_POST['aufbau']);
$_POST['motor'] = cl($_POST['motor']);
$_POST['ps'] = cl($_POST['ps']);
$_POST['hubraum'] = cl($_POST['hubraum']);
$_POST['sonstiges'] = cl($_POST['sonstiges']);
$_POST['beschreibung'] = cl($_POST['beschreibung']);
$img = getimagesize($_FILES['foto']['tmp_name']);
if($img[2] == 1){$dat_end = '.gif';
}
elseif($img[2] == 2){$dat_end = '.jpg';
}
elseif($img[2] == 3){$dat_end = '.png';
}
else {$dat_end = '';
}
if(empty($dat_end)){echo 'Ungültige Datei!';
}
else {$rand = time() . rand(1,999999);
$path = $rand . $dat_end;
move_uploaded_file($_FILES['foto']['tmp_name'],'fotos/' . $path);
$sql = "INSERT INTO `blitz` (`user`,`model`,`jahr`,`aufbau`,`motor`,`ps`,`hubraum`,`sonstiges`,`beschreibung`,`path`,`time`) VALUES ('" . $_POST['user'] . "','" . $_POST['model'] . "','" . $_POST['jahr'] . "','" . $_POST['aufbau'] . "','" . $_POST['motor'] . "','" . $_POST['ps'] . "','" . $_POST['hubraum'] . "','" . $_POST['sonstiges'] . "','" . $_POST['beschreibung'] . "','" . $path . "','" . time() . "')";
mysql_query($sql);
echo 'Foto hochgeladen!';
}
}
mysql_close();
?>