First file:
<?php
$db_server = MySQL_connect($db_hostname, $db_username, $db_password);
mysql_select_db('Mailinglist')or die("Unable to select database: " . mysql_error());
$sqlquery = "SELECT * from Maildata";
$queryresult = mysql_query($sqlquery);
echo "<table width=700 border=1 align=center>";
echo " <tr>";
echo "<td width=200> <center><b>Name</b></center></td>\n";
echo "<td width=200> <center><b>e-mail</b></center></td>\n";
echo "<td width=200> <center><b>Secondary email</b></center></td>\n";
echo " <td width=100> <center><b>Action</b></center></td>\n";
echo " </tr>\n";
while ($row=mysql_fetch_array($queryresult)){
echo " <tr>\n";
echo " <td>".$row["Name"]."</td>\n";
echo " <td>".$row["Email"]."</td>\n";
echo " <td>".$row["Secondaryemail"]."</td>\n";
echo " <td><a href=\"display.php?Email=".$row["Email"]."\">edit</a></td>\n";
echo " </tr>\n";
}
echo "</table>\n";
?>
/* Here through edit we try to change the value entered in database. once we click on edit it takes to page display.php. */
<html>
<head>
<title>Mail record update form</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="maildata" method="post" action="update.php">
<table width="250" border="1" align="center">
<?php
require_once 'login.php';
$db_server = MySQL_connect($db_hostname, $db_username, $db_password);
$selectdb=mysql_select_db("Mailinglist") or die("Could not select mail data database !");
extract($_REQUEST, EXTR_SKIP);
$sqlquery = "SELECT * from Maildata";
$queryresult = mysql_query($sqlquery);
if($row=mysql_fetch_array($queryresult)){
echo "<tr> ";
echo " <td> Name </td>";
echo " <td width=\"150\">". $row["Name"] . " </td>";
echo "</tr>";
echo "<tr> ";
echo " <td> e-mail </td>";
echo " <td>". $row["Email"]."</td>";
echo " <td> <input type=\"hidden\" Name=\"Email\"value=\"".$row["Secondaryemail"]."\" ></td>";
echo "</tr>";
echo " <tr> ";
echo " <td> secondarye-mail </td>";
echo " <td> ";
echo " <input type=\"text\" Name=\"Secondaryemail\" value=\" ".$row["Secondaryemail"]."\">";
echo " </td>";
echo "</tr>";
echo "<tr> ";
echo " <td> ";
echo " <center> ";
echo " <input type=\"submit\"name=\"Submit\" value=\"Submit\">";
echo " </center>";
echo " </td>";
echo "</tr>";
}
?>
</table>
</form>
</body>
</html>
Here we try to change value like example1@example.com to example1 and click on submit button. Here it will take to file update.php
<html>
<head>
<title>New record In Newsmail table</title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>*</p>
<?php
require_once 'login.php';
$db_server = MySQL_connect($db_hostname, $db_username, $db_password);
$selectdb=mysql_select_db("Mailinglist") or die("Could not select mail data database !");
extract($_REQUEST, EXTR_SKIP);
$sqlquery = "UPDATE Maildata SET Secondaryemail=\"".$secondaryemail."\" where Email=\"".
$Email."\"";
echo $sqlquery;
$result = mysql_query($sqlquery)or die("Could not execute SQL query");
if(!$result){
die("Unable to insert data into table maildata:".'<br />'.mysql_error());
}
echo " Record was successfully updated.";
?>
</body>
</html>
We get output as UPDATE Maildata SET Secondaryemail="" where Email="example1@example.com" Record was successfully updated. But database wont get updated.
In table maildata only one record is there with fields Name, Email and secondarymail values satish, example2@example.com and example1@example.com
one.txt