Falls du noch im Vorhinein eine Prüfung der variabel durchführen mächtest wäre folgender Code sinnvoll:
PHP-Code:
function sqlstr(&$addr, $def = ""){ // $addr : referencevariable , $def : default value
if(isset($addr)){
$addr = mysql_real_escape_string($addr); // reference = querystring for later use and return value
}else{
$addr = $def; // reference = default value and return value
}
return $addr; // return reference
}
$eintrag = "INSERT INTO tabelle (id, beta, zeit)
VALUES ('', '" . sqlstr($_POST['beta']) . "', '" . time() . "')";
// reference and $_POST['beta'] correlate and is available for later use
// time() makes perfectly sense here because datebase server and php server may differ
$eintragen = mysql_query($eintrag)or die(__LINE__ .':'. mysql_error());
// why first setting a variable for one single use?
if($_POST['beta'] === ""){ // $_POST['beta'] can be used now without hesitation because setted for sure due to sqlstr
// make that and make this...
}
Kommentar