hejsa
Jeg er meget ny til php, og jeg har problemer med at få min update form til at opdatere min database.
jeg bruger et script, som jeg har funder på nettet, og modificeret på:
<?php require_once("includes/connection.php");
// Select all data records in table "name_list" and put them into $result.
$result=mysql_query("SELECT * FROM nyheder ORDER BY id ASC");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
<title>Untitled Document</title></head>
<body>
<form id="form1" name="form1" method="post" action="update.php">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td align="center" bgcolor="#FFCC00"><strong>ID</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Emne</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Indhold</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Billede</strong></td>
</tr>
<?php
// Fetch record rows in $result by while loop and put them into $row.
while($row=mysql_fetch_assoc($result)){
?>
<tr>
<td bgcolor="#FFFFCC"><?php echo $row['dato']; // Show record's Date ?></td>
<td bgcolor="#FFFFCC"><input name="emne_<?php echo $row['id']; ?>" type="text" id="emne_<?php echo $row['id']; ?>" value="<?php echo $row['emne']; ?>" size="50" /></td>
<td bgcolor="#FFFFCC"><textarea name="indhold_<?php echo $row['id']; ?>" cols="50" rows="5" id="indhold_<?php echo $row['id']; ?>"><?php echo $row['indhold']; ?></textarea></td>
<td bgcolor="#FFFFCC"><input name="billede_<?php echo $row['id']; ?>" type="text" id="billede_<?php echo $row['id']; ?>" value="<?php echo $row['billede']; ?>" size="50" /></td>
</tr>
<?php } // End while loop. ?>
</table>
<input type="submit" name="Submit" value="Update" />
</form>
</body>
</html>
og den sender så til en update.php fil:
<?php
if($_POST['Submit']){ // If receive Submit button variable.
require_once("includes/connection.php");
// Select all data records in table "name_list" and put them into $result.
$result=mysql_query("SELECT id FROM nyheder ORDER BY id ASC");
// Fetch record rows in $result by while loop and put them into $row.
while($row=mysql_fetch_assoc($result)){
// Get the posted value "name_ID value" from form.php. This variable change it's value by while loop.
$emne=$_POST["emne_".$row['id']];
$indhold=$_POST["indhold_".$row['id']];
$billede=$_POST["billede_".$row['id']];
// Update field "name", matching with "id" value by while loop.
mysql_query("UPDATE nyheder SET emne='{$emne}', indhold='{$indhold}', billede='{$billede}', WHERE id='{$row['id']}'");
}
echo "--- Update Complete ---";
}
?>
som sagt jeg er meget ny til php, så det ville være rart hvis en af jer kunne fortælle mig hvor jeg har lavet fejl?