View Full Version : updating (changing) mysql db with html table

08-20-2007, 05:35 PM
I wish to use one html-page to view and change entries in a db. Here is the code I got so far, but when clicking "save", it will just display the original data without updating.

$id = '1';
// Update the database if form posted
if ($save) {
echo "updated <p>" ;
$update = mysql_query("UPDATE distributoren Set Firma = $txtFirma, Land = $txtLand WHERE id = $id") or die("SQL Update failed");
$query_distributoren = "SELECT * FROM distributoren WHERE id = $id";

$distributoren = mysql_query($query_distributoren) or die(mysql_error());
$row_distributoren = mysql_fetch_assoc($distributoren);


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="txtId" value="<? echo $id; ?>">

<input type="text" name="txtFirma"value="<?php echo $row_distributoren['Firma']; ?>"/>
<br />
<input type="text" name="txtLand" value="<?php echo $row_distributoren['Land']; ?>" />
<br />

<input type="submit" name="save" value="Save">


What's wrong? Thanks.

08-20-2007, 05:44 PM
You can redirect the page to itself once you have updated the database.

for example

// start saving data into data base
// and if successful, redirect page to itself to refresh page.
header("location: " . $_SERVER['PHP_SELF']);

08-20-2007, 10:58 PM
echo "updated <p>" ; // after this line add:
$txtFirma = $_POST['txtFirma'];
$txtLand = $_POST['txtLand'];
You may want to echo() the query before you execute it too to make sure that it's properly formatted and possibly run it from phpMyAdmin.

You can redirect the page to itself once you have updated the database.

There's no reason to do that.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum