Updating information in MySQL database

Hi all,

I’m trying to get something to update to a MySQL database. I’ve managed to get the information in there using a form, display all current entries but can’t get the form to update the exisiting data.

My main page that shows the data is:

<?php
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="xxxx"; // Database name
$tbl_name="xxxx"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="0" cellspacing="20" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['id']; ?></td>
<td><? echo $rows['COUNTRY']; ?></td>
<td><? echo $rows['PHONE']; ?></td>


<td align="center"><a href="contacts_magazines_editdetails.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>

It then links through to the following page which has the update form. The exisitng data does show in the fields:

<?php
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="xxxx"; // Database name
$tbl_name="xxxx"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];


// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="contacts_magazines_editdetails_submit.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="NAME" type="text" id="NAME" value="<? echo $rows['NAME']; ?>"></td>
<td align="center"><input name="COUNTRY" type="text" id="COUNTRY" value="<? echo $rows['COUNTRY']; ?>" size="15"></td>
<td><input name="PHONE" type="text" id="PHONE" value="<? echo $rows['PHONE']; ?>" size="15"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection
mysql_close();

?>

Then when the user clicks submit it goes here to update the database:

<?php
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="xxxx"; // Database name
$tbl_name="xxxx"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// update data in mysql database
$sql="UPDATE $tbl_name SET NAME='$NAME', COUNTRY='$COUNTRY', PHONE='$PHONE' WHERE id='$id'";
$result=mysql_query($sql);

// if successfully updated.
if($result){
echo "";
}

else {
echo "ERROR";
}

?>
<head>
<META HTTP-EQUIV="refresh" CONTENT="seconds;URL=contacts_magazines_added.php">
</head>

</body>
</html>

It would seem that it works, it says that it has sucessfully updated the information but when you go to check the info is still as it was before.

I can’t figure it out! It’s driving me mental!

Any ideas anyone?