Hi folks. I have a problem with my code. basically i have three files to update a database table in mysql. the first
<?php
$connection = mysql_connect('localhost');
$db = @mysql_select_db(marcat, $connection);
?>
<html>
<head>
<title>MarCat Buyer Update</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" link="#0000FF"
vlink="#000080" alink="#FF0000">
<p align="center"><img src="images/logo.gif" width="850" height="89"></p>
<p>
<center>
<h2>MarCat Buyer Update Page</h2>
</center>
<p>
<hr>
<form action="modify_buyer_results.php" method="POST">
<table border="1" >
<tr>
<td>BUYERS</td>
<td>
<?php
echo '<form><select name=Name>';
$names = mysql_query("SELECT Name FROM BUYERS ORDER BY Name");
while ($row = mysql_fetch_array($names))
{
$name_entry=$row["Name"];
echo "<option value=$name_entry>$name_entry\n";
}
echo "</form>";
?>
</td>
<td>
<input type="Submit" name="submit" value="Select Buyer">
</td>
</tr>
</table>
<p>
<hr><p>
</body>
</html>
connects to the database and lists the 'Name' field of the BUYERS table and allows you to select one "name" and then calls the next file.
the second file.
<html>
<head>
<title>MarCat Buyer Update</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" link="#0000FF"
vlink="#000080" alink="#FF0000">
<p align="center"><img src="images/logo.gif" width="850" height="89"></p>
<p>
<center>
<h2>MarCat Buyer Update Page</h2>
</center>
<p>
<hr>
<?php
$connection = mysql_connect('localhost');
$db = @mysql_select_db(marcat, $connection);
$database_name = $_POST['Name'];
$query = " SELECT *
FROM BUYERS
WHERE Name = '$database_name'";
$result = mysql_query($query);
$buyers = mysql_fetch_array($result);
mysql_close();
?>
<form action="buyer_updated.php" method="POST">
<input type="hidden" name ="database_name" value=" <php echo $database_name; ?> ">
<table border="0">
<tr>
<td>Name: </td><td><input type="text" name="ud_name" value="<? echo "$buyers[Name]"?>"></td>
</tr>
<tr>
<td>Address: </td><td><input type="text" name="ud_address" value="<? echo "$buyers[Address]"?>"></td>
</tr>
<tr>
<td>Phone: </td><td><input type="text" name="ud_phone" value="<? echo "$buyers[Phone]"?>"></td>
</tr>
<tr>
<td>Company: </td><td><input type="text" name="ud_company" value="<? echo "$buyers[Company]"?>"></td>
</tr>
<tr>
<td>ABN: </td><td><input type="text" name="ud_abn" value="<? echo "$buyers[ABN]"?>"></td>
</tr>
<tr>
<td colspan="2"><input type="Submit" value="Update Buyer"></td>
</table>
</form>
<hr>
</body>
</html>
selects all fields in the BUYERS table for the name specified and displays these values in a form that allows you to modify the values, which then calls file three.
file three updates the fields and echo's Record Updated.
<html>
<head>
<title>MarCat Buyer Update</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" link="#0000FF"
vlink="#000080" alink="#FF0000">
<p align="center"><img src="images/logo.gif" width="850" height="89"></p>
<p>
<center>
<h2>MarCat Buyer Update Page</h2>
</center><p><hr>
<?php
$database_name = $_POST['database_name'];
$ud_name=$_POST['ud_name'];
$ud_address=$_POST['ud_address'];
$ud_phone=$_POST['ud_phone'];
$ud_company=$_POST['ud_company'];
$ud_abn=$_POST['ud_abn'];
$connection = mysql_connect('localhost');
$db = @mysql_select_db(marcat, $connection);
$query="UPDATE BUYERS SET Name='$ud_name', Address='$ud_address', Phone='$ud_phone', Company='$ud_company', ABN='$ud_abn' WHERE Name='$database_name' ";
mysql_query($query) or die(MySQL_Error());
echo "Record Updated";
mysql_close();
?>
<hr>
</body>
</html>
the first two file appear to be working but the third doesn't work, ie as in updating the database. the echo part works in the third file but the query doesn't....
can anyone see what i am doing wrong or suggest a better way of doing it?
cheers
Joe