I did a var dump and got
Array
(
[id] => 81
)
Array
(
)
string(2) "81"
Here are all the pages. first retrieve.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>VIP Database</title>
<!-- Styling for Search Button-->
<style type="text/css">
.style1 {
float: right;
color: #FF0000;
}
.fieldset1 {
float: top;
border-top-style: double;
border-right-style: double;
border-bottom-style: double;
border-left-style: double;
border-top-color: #9900FF;
border-right-color: #9900FF;
border-bottom-color: #9900FF;
border-left-color: #9900FF;
}
</style>
</head><head>
<title>Search the Database</title>
</head>
</html>
<?php
// Make a MySQL Connection
mysql_connect("localhost", "xxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
// Get all the data from the "xxx" table
$result = mysql_query("SELECT * FROM vip ORDER by fname ASC")
or die(mysql_error());
$query = mysql_query("SELECT * FROM vip");
$number=mysql_num_rows($query);
$id = $_POST['id'];
echo "<TABLE BORDER='3' CELLPADDING='10' CELLSPACING='10' ALIGN = 'CENTER'><TD>";
echo "<table border='0' align = 'center'>";
echo "<tr> <th></th><th colspan='4'><font color='#FF0000' align = 'right'>Search the VIP Database</th> <th><form action='search.php' method='post'> <input name='term' type='text' class='style1'></th> <th colspan='2'><input name='submit' type='submit' class='style1' value='Search'</th> </tr>";
echo "<tr> <th bgcolor='#f2f0eb'>Total VIP's = $number </th> <th colspan='9' bgcolor='#f2f0eb'>VIP Database - Order By First Name</th> </tr>";
echo "<tr> <th width='130'><p><span><a href='registervip.html'>Add VIP</a></span></p></th> <th>First Name</th> <th>Last Name</th> <th>Birthday Month</th> <th>Mobile</th> <th>Email</th> <th>Subscribe</th> <th>Welcome</th> <th>Edit</th> <th>Delete</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
if($color==1){
echo "<tr bgcolor='#f2f0eb'><td>";
echo "</td>";
echo "<td>";
echo $row['fname'];
echo "</td><td>";
echo $row['lname'];
echo "</td><td>";
echo $row['month_birth'];
echo "</td>";
echo "<td>";
echo $row['mobile'];
echo "</td><td>";
echo $row['email'];
echo "</td>";
echo "<td>";
//echo $row['subscribe'];
echo $row['subscribe'] ? 'Yes' : 'No';
echo "</td><td>";
echo $row['welcome'] ? 'Yes' : 'No';
echo "</td><td>";
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr bgcolor='#EEEEEE'><td>";
echo "</td>";
echo "<td>";
echo $row['fname'];
echo "</td><td>";
echo $row['lname'];
echo "</td><td>";
echo $row['month_birth'];
echo "</td>";
echo "<td>";
echo $row['mobile'];
echo "</td><td>";
echo $row['email'];
echo "</td>";
echo "<td>";
echo $row['subscribe'] ? 'Yes' : 'No';
echo "</td><td>";
echo $row['welcome'] ? 'Yes' : 'No';
echo "</td><td>";
$color="1";
}
?>
<span><a href="edit.php?id=<? echo $row['ID']; ?>">Edit</a></span>
<td><a href="delete.php?id=<? echo $row['ID']; ?>"onclick="return confirm('Are you sure you want to delete <? echo $row ['fname']." ". $row ['lname']?> ?');"><font color="red"> DELETE </font></a></span></td>
</tr>
<?php
}
echo "</table>";
echo "</TABLE>";
?>
</html>
now the edit.php
<pre>
<?php
print_r($_GET);
print_r($_POST);
?>
</pre>
<?php
$host="localhost"; // Host name
$username="xxx"; // Mysql username
$password="xxx"; // Mysql password
$db_name="xxxxx"; // Database name
$tbl_name="xxx"; // Table name
// Make a MySQL Connection
mysql_connect("localhost", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
// get value of id that sent from address bar
$id= (int) $_GET['id'];
var_dump($_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="update.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>First Name</strong></td>
<td align="center"><strong>Last Name</strong></td>
<td align="center"><strong>Month Of Birth</strong></td>
<td align="center"><strong>Mobile</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Subscribe</strong></td>
<td align="center"><strong>Welcome</strong></td>
</tr>
<tr>
<td> </td>
<td align="center"><input name="fname" type="text" id="fname" value="<? echo $rows['fname']; ?>"></td>
<td align="center"><input name="lname" type="text" id="lname" value="<? echo $rows['lname']; ?>" size="15"></td>
<td align="center"><input name="month_birth" type="text" id="month_birth" value="<? echo $rows['month_birth']; ?>" size="15"></td>
<td align="center"><input name="mobile" type="text" id="mobile" value="<? echo $rows['mobile']; ?>" size="15"></td>
<td><input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="30"></td>
<td><input name="subscribe" type="text" id="subscribe" value="<? echo $rows['subscribe']? 'Yes' : 'No'; ?>"size="7"></td>
<td><input name="welcome" type="text" id="welcome" value="<? echo $rows['welcome']? 'Yes' : 'No'; ?>" size="7"></td>
<tr>
<td> </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> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?
// close connection
mysql_close();
?>
now the update.php
<head>
<!--<meta http-equiv="refresh" content="2; URL=retrieve.php"> -->
</head>
<?php
$host="localhost";
$username="xxxx";
$password="xxxxx";
$database="xxxxx";
$table="xxxx";
// Make a MySQL Connection
mysql_connect("$host","$username","$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());
$fname= mysql_real_escape_string($_POST['fname']);
$lname= mysql_real_escape_string($_POST['lname']);
$address= mysql_real_escape_string($_POST['address']);
$month_birth= mysql_real_escape_string($_POST['month_birth']);
$mobile= mysql_real_escape_string($_POST['mobile']);
$email=mysql_real_escape_string($_POST['email']);
$subscribe=mysql_real_escape_string($_POST['subscribe']);
$welcome=mysql_real_escape_string($_POST['welcome']);
// get value of id that sent from address bar
$id= (int) $_GET['id'];
// update data in mysql database
$sql="UPDATE $table SET fname='$fname', lname='$lname', month_birth='$month_birth', mobile='$mobile', email='$email', subscribe='$subscribe', welcome='$welcome' WHERE id='$id'";
echo $sql;
$res=mysql_query($sql) or die ("Error: ". mysql_error(). " with query ". $sql);
echo 'rows updated:' . mysql_affected_rows();
echo "<br />Record Successfully Updated";
?>