Fejl ved oprettelse af bruger
Følgende fejl får vi ved oprettelse af bruger:Warning: Cannot modify header information
- headers already sent by (output started at
c:\wamp\www\plas\~phpdesigner_outputlocal_tmp~6749.php:10)
in c:\wamp\www\plas\~phpdesigner_outputlocal_tmp~6749.php on line 78
Koden er:
<html>
<head>
<title>
Oprettelse
</title>
</head>
<body>
<?php
// kobler til db server, dog uden password
$dbcnx = @mysqli_connect("localhost", "root", "");
if (!$dbcnx) {
echo( "<p>Unable to connect to the database server at this time.</p>" );
exit();
}
//kobler til db, register
if (! @mysqli_select_db($dbcnx,"register") ) {
echo( "<p>Unable to locate the register database at this time.</p>" );
exit();
}
?>
<table cellspacing="10">
<tr>
<th>Brugernavn</th>
<th>Fornavn</th>
<th>Efternavn</th>
<th>Adresse</th>
<th>Post nr.</th>
<th>By</th>
<th>Telefon</th>
<th>Fax</th>
<th>Email</th>
<th>Stilling</th>
</tr>
<?php
//henter data fra ansatte tabellen
$sql = 'SELECT * FROM ansatte ORDER BY efternavn';
$result = mysqli_query($dbcnx,$sql);
while ($row=mysqli_fetch_assoc($result)){
echo '<tr>
<td>'.$row['user_name']. '</td>
<td>'.$row['fornavn']. '</td>
<td>'. $row['efternavn'].'</td>
<td>'. $row['adresse'].'</td>
<td>'. $row['postnr'].'</td>
<td>'. $row['bynavn'].'</td>
<td>'. $row['tlf'].'</td>
<td>'. $row['fax'].'</td>
<td>'. $row['email'].'</td>
<td>'. $row['status'].'</td>
</tr>';
}
?>
</table>
<?php
// Har brugeren klikket på Opret?
if ($_POST['opret']=='opret'){
$sql="INSERT INTO ansatte SET
user_name='" . $_POST['user_name'] . "',
password='" . $_POST['password'] . "',
fornavn='" . $_POST['fornavn'] . "',
efternavn='" . $_POST['efternavn'] ."',
adresse='" . $_POST['adresse'] ."',
postnr='" . $_POST['postnr'] ."',
bynavn='" . $_POST['bynavn'] ."',
tlf='" . $_POST['tlf'] ."',
fax='" . $_POST['fax'] ."',
email='" . $_POST['email'] ."',
status='" . $_POST['status'] ."'";
$result = @mysqli_query($dbcnx,$sql);
if (!$result) {
echo("<p>Error performing query: " . mysqli_error($dbcnx) . "</p>");
exit();
}
header("Location:register.php");
}
?>
<!--til at oprette -->
<form name="opret" method="POST" action="<?php echo $_SERVER['PHP_SELF']?>">
Brugernavn:
<input type="text" name="user_name">
<br />
Password:
<input type="password" name="password">
<br />
Fornavn:
<input type="text" name="fornavn">
<br />
Efternavn:
<input type="text" name="efternavn">
<br />
Adresse:
<input type="text" name="adresse">
<br />
Post nr.:
<input type="text" name="postnr">
<br />
By:
<input type="text" name="bynavn">
<br />
Telefon:
<input type="text" name="tlf">
<br />
Fax:
<input type="text" name="fax">
<br />
Email:
<input type="text" name="email">
<br />
Stilling:
<input type="text" name="status">
<!-- hentet fra opret.php
<?php
while ( $row = mysqli_fetch_assoc($result) ) {
$val = $row['Code'];
$navn = $row['Name'];
echo "<option value=\"$val\">$navn</option>\n";
}
?>-->
</select>
<br>
<input type="submit" name="opret" value="opret">
</form>
</body>
</html>
Vi ønsker at siden opdateres ved oprettelse af en ny bruger således at vi kommer tilbage til samme side, men hvor tabellen med den nyoprettede bruger er på.
Håber der er en, der vil hjælpe.
På forhånd tak.
