Jump to content

update row


OHannesson

Recommended Posts

hi there,

I do want to ask you out there if you could help me here out.

<?php
include 'main.php'; 
include 'db.inc.php';
?>

<?php
if(isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = 'bugl';
}

if($action == 'edit' and isset($_GET['fnumber'])) {
if(isset($_POST['fnumber'])) {
	echo $_POST['location'];
	echo $_POST['notes'];

	$location = $_POST['location'];
	$notes = $_POST['notes'];
	$fnumber = $_POST['fnumber'];

	$sqlUP = @mysql_query("UPDATE 'hestur' SET 'location' = '$location', 'notes' = '$notes' WHERE 'fnumber' = '$fnumber'");

    if(mysql_affected_rows() == 0)
    {
      print"not updated?<br>";
    }
    
	if (!$sqlUP) {
		echo '<a href="check.php">';
	} else {
		echo '<p>Error updating details: ' . mysql_error() . '</p>';
	}


} else {
	$fnumber = $_GET['fnumber'];
	$list = @mysql_query("SELECT id, fnumber, name, ffnumber, fname, mfnumber, fname, location, notes FROM hestur WHERE fnumber='$fnumber'");

	if (!$list) {
	    exit('<p>Error fetching horse details: ' . mysql_error() . '</p>');
	}

	$horseList = mysql_fetch_array($list);

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
		<table cellspacing="10px">
	        <tr>
	          <td>id
	          <td><?php echo $horseList['id']; ?>
	        </tr>
			<tr>
	          <td>ID number:
	          <td><?php echo $horseList['fnumber']; ?>
	        </tr>
	        <tr>
	          <td>Name:
	          <td><?php echo $horseList['name']; ?>
	        </tr>
			<tr>
	          <td>Location:
	          <td><input type="text" name="location" value="<?php echo $horseList['location']; ?>" />
	        </tr>
	        <tr>
	          <td>Notes:
	          <td><input type="text" name="notes" value="<?php echo $horseList['notes']; ?>" />
	        </tr>
	        </table>
			<input type="hidden" name="fnumber" value="<?php echo $fnumber; ?>" />
			<input type="submit" value="Submit" name="submitEdit" />


<?php	
}

} elseif($action == 'del' and isset($_GET['fnumber'])) {
$id = $_GET['fnumber'];

$sql = "DELETE FROM hestur WHERE fnumber = '$id'";
if(@mysql_query($sql)) {
	echo '<p>Your horse has been successfully deleted from the database!</p>';
	echo '<p>Press <a href="check.php">here</a> to return!</p>';
} else {
	echo '<p>There is a problem: ' . mysql_error() . '</p>';
}

//	header('location: ' . $_SERVER['PHP_SELF']);
exit();
}
?>

<form action="reports.php" method="post">
<p><h2>The following horses are registered in the database: </h2></p>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<th>  </th>
<th>  </th>
<th>ID number</th>
<th>Name </th>
<th>Location </th>
<th></th>
</tr>
<?php
$sql1 = "SELECT * FROM hestur";
$list = @mysql_query($sql1);
if(!$list) {
exit('Database error: ' . mysql_error());
}

if(mysql_num_rows($list) > 0) {
while($l = mysql_fetch_array($list)) {
	?>
<tr valign="top">
	<td></td>
	<td><?php echo $l['id']; ?>.</td>
	<td><?php echo $l['fnumber']; ?></td>
	<td><?php echo $l['name']; ?></td>
	<td><?php echo $l['location']; ?></td>
	<td>[ <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=edit&fnumber=<?php echo $l['fnumber']; ?>" onclick="return confirm('Are your sure you want to edit the information about this horse?');">Edit</a> |
    	<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=del&fnumber=<?php echo $l['fnumber']; ?>" onclick="return confirm('Delete this horse from the database?');">Delete</a> ]</td>
    	<td><input type=checkbox name='box[]' value='<?php echo $l['name']; ?>'></td>
</tr>
<?php
}
} else {
?>
<tr><td colspan="3">No horses</td></tr>
<?php
}
?>
<tr><td></td><td></td><td><input type="submit" value="Submit" name="submit" /></td></tr>
</form>
</table>
<br />
<p> </p>


<?php include 'footer.php' ?> 

 

I have a data pulled from a database and I can either choose to delete the data from the database or edit it.

 

somehow the update does not work. Now I have sat over this for awhile and I just don´t see what is the problem. Is there anyone out there kind enough to help me with this and point out what I am doing wrong and suggestions on how to fix this.

mysql_affected_rows() does not print out anything

 

many thanks in advance

OH

Link to comment
https://forums.phpfreaks.com/topic/99235-update-row/
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.