Hi Guyes,
I m retriving Company name from 'clients' table which have separate 'id'. I m retrivig them in a drop down list box (see zip file). But when i m selecting 1 of them & press update, then it is updating as id, not name.
I mean in list box, if company name "abc (id=1)" & if i select "bcd (id=2)", then its updating with id = 2, not 'bcd'...
MOD EDIT: Zip removed - PHP scripts can be embedded in your post...
editPage.php:
<?php
include "connect.inc";
connect();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Practice for dropdown list</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#666600">
<script language="JavaScript">
function val(){
if(f1.id.value == 0){
alert("Select Company Name");
return false;
}
}
</script>
<h3 align="center"><u>Edit Page</u></h3><p>
<table width="27%" border="1" align="center">
<form name="f1" action="edit.php" method="post" onSubmit="return val()">
<input type="hidden" name="posted" value="true">
<tr>
<td>Company Name</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value=" Submit "></td>
</tr>
</form>
</table>
</body>
</html>
editSuccess.php:
<?php
include "connect.inc";
connect();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Practice for dropdown list</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#666600">
<h3 align="center"><u>Update Success Page</u></h3>
<p>
<?php
$id = $_POST[id];
$cname = $_POST[cname];
$adrs = $_POST[adrs];
if(isset($_POST[posted])){
$q1 = "UPDATE clients SET name='$cname', address = '$adrs' WHERE id = '$id'";
$r1 = mysql_query($q1);
if($r1){
echo "Successfull Update of id No : $id<br>";
echo "<u><font color = blue>Your New Information</font></u>: "."<BR>";
echo "Company Name : ".$name."<BR>";
echo "Company Address : ".$adrs."<BR>";
}else{
echo "Failed to Update<br>";
echo mysql_error();
}
}
?>
<p><a href="index.php">BACK To Inbox</a>
</body>
</html>