Jump to content

Whats wrong with my script?


Mutley

Recommended Posts

It lists the fields from the database so you can edit them but every time I try to update them, it updates the wrong one, the same one every time, id 5.

Form file:

[code]<?php
require_once("connection.php");

mysql_select_db("rufc");

$result = mysql_query("SELECT id, image, caption, date, DATE_FORMAT(date,'%d-%m-%Y') AS dstamp FROM caption ORDER BY date DESC LIMIT 3");
while($row = mysql_fetch_array( $result ))
    {
?>
<form action="caption/update_confirm.php" method="POST">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">

<table width="90%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><center><img src="<?=$row['image'];?>" /></center></td>
  </tr>
  <tr>
    <td><center><?=$row['dstamp'];?></center></td>
  </tr>
  <tr>
    <td><center><input class="form" type="text" size="20" name="home" value="<?=$row['caption']; ?>"></center></td>
  </tr>
</table>

<input class="form" type="submit" value="Submit">
 
<?php
  }
?>
</table>
[/code]



Update database file:

[code]<?php
ob_start();
include("config.php");

require_once("connection.php");

$id = $_POST['id'];
$image = $_POST['image'];
$caption = $_POST['home'];
$date = $_POST['date']; // what's the date?
list($day, $month, $year) = explode("-", $date); // now split it up
$update = date('Y-m-d', strtotime("$year/$month/$day")); // now re-form it

mysql_select_db("rufc");

$sql = "UPDATE caption SET caption='$caption' WHERE id = '".$id."' LIMIT 1";
mysql_query($sql);

  echo "The selected information was updated!";
  echo "<a href='caption.php'>Click here</a> to continue";
?>
[/code]

Any idea?
Link to comment
https://forums.phpfreaks.com/topic/30498-whats-wrong-with-my-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.