updating problem in mysql
Posted: Sun Dec 21, 2003 11:25 pm
Hi folks. I have a problem with my code. basically i have three files to update a database table in mysql. the first
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.
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.
File three doesn't appear to be working, can i call
any help appreciated
cheers,
confused....
Code: Select all
<?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>the second file.
Code: Select all
<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">
<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>file three updates the fields and echo's Record Updated.
Code: Select all
<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ї'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 WHERE Name='$database_name' SET Name='$ud_name' Address='$ud_address' Phone='$ud_phone' Company='$ud_company' ABN='$ud_abn'";
mysql_query($query);
echo "Record Updated";
mysql_close();
?>
<hr>
</body>
</html>in the third file from the first file or is there another problem that i can't see..$database_name = $_POST['Name'];
any help appreciated
cheers,
confused....