任何人都可以帮我吗?我想在我的数据库中编辑一条记录。一切正常。如果我点击按钮,它会保存记录。但它并没有将我重新引导回transparente.php!我刚得到一个白色网站...... 请帮助我!
<?php
define('INCLUDE_CHECK',true);
require 'connect.php';
require 'functions.php';
session_name('tzLogin');
session_set_cookie_params(7*24*60*60);
session_start();
if(isset($_GET['logoff']))
{
$_SESSION = array();
session_destroy();
header("Location: demo.php");
exit;
}
function renderForm($id, $Name, $Wer, $Erhalten, $Digital, $Betrag, $Bezahlt, $Anmerkung, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Eintrag bearbeiten</title>
</head>
<body>
<?php
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div>
<p><strong>ID:</strong> <?php echo $id; ?></p>
<strong>Firma</strong><input type="text" name="Name" value="<?php echo $Name; ?>"/><br/>
<strong>Wer</strong><input type="text" name="Wer" value="<?php echo $Wer; ?>"/><br/>
<strong>Erhalten</strong><input type="text" name="Erhalten" value="<?php echo $Erhalten; ?>"/><br/>
<strong>Digital</strong><input type="text" name="Digital" value="<?php echo $Digital; ?>"/><br/>
<strong>Betrag</strong><input type="text" name="Betrag" value="<?php echo $Betrag; ?>"/><br/>
<strong>Bezahlt</strong><input type="text" name="Bezahlt" value="<?php echo $Bezahlt; ?>"/><br/>
<strong>Anmerkung</strong><input type="text" name="Anmerkung" value="<?php echo $Anmerkung; ?>"/><br/>
<input type="submit" name="submit" value="Speichern">
</div>
</form>
</body>
</html>
<?php
}
include('db.inc.php');
if (isset($_POST['submit']))
{
if (is_numeric($_POST['id']))
{
$id = $_POST['id'];
$Name = mysql_real_escape_string(htmlspecialchars($_POST['Name']));
$Wer = mysql_real_escape_string(htmlspecialchars($_POST['Wer']));
$Erhalten = mysql_real_escape_string(htmlspecialchars($_POST['Erhalten']));
$Digital = mysql_real_escape_string(htmlspecialchars($_POST['Digital']));
$Betrag = mysql_real_escape_string(htmlspecialchars($_POST['Betrag']));
$Bezahlt = mysql_real_escape_string(htmlspecialchars($_POST['Bezahlt']));
$Anmerkung = mysql_real_escape_string(htmlspecialchars($_POST['Anmerkung']));
if ($Name == '')
{
$error = 'ERROR: Please fill in all required fields!';
renderForm($id, $Name, $Wer, $Erhalten, $Digital, $Betrag, $Bezahlt, $Anmerkung, $error);
}
else
{
mysql_query("UPDATE Transparente SET
Name='$Name',
Wer='$Wer',
Erhalten='$Erhalten',
Digital='$Digital',
Betrag='$Betrag',
Bezahlt='$Bezahlt',
Anmerkung='$Anmerkung'
WHERE id='$id'")
or die(mysql_error());
header("Location: transparente.php");
}
}
else
{
echo 'Error!';
}
}
else
{
numeric/larger than 0)
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM Transparente WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$Name = $row['Name'];
$Wer = $row['Wer'];
$Erhalten = $row['Erhalten'];
$Digital = $row['Digital'];
$Betrag = $row['Betrag'];
$Bezahlt = $row['Bezahlt'];
$Anmerkung = $row['Anmerkung'];
renderForm($id, $Name, $Wer, $Erhalten, $Digital, $Betrag, $Bezahlt, $Anmerkung, '');
}
else
{
echo "No results!";
}
}
else
{
echo 'Error!';
}
}
?>
答案 0 :(得分:1)
设置输出后,重定向不起作用。将重定向逻辑移到顶部。 希望这会有所帮助。