Forum Moderators: coopster

Message Too Old, No Replies

Update in PHP

Php

         

leenakrishnaa

7:00 am on Jan 2, 2009 (gmt 0)

10+ Year Member



Please tell me how to update the field after the code i have given below.....

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hai", $con);

$sql = "SELECT FirstName,LastName,Age FROM persons where Age='12'";

$result = @mysql_query($sql, $con) or die("Cannot execute query.". mysql_error());
$numrow = mysql_num_rows($result);
if ($numrow != 0)
{
// fetch each record in result set
for ($counter == 0; $row = mysql_fetch_row($result); $counter++)
{
// build table to display result
print ("<form action='pp1.php' method='post'><h2><center>Member Profile</center></h2>");
print ("<table border = '1' cellpadding = '3' cellspacing = '2' style = 'background-color: #ADD8E6'>");
print ("<tr>");
print ("<th>Firstname</th>");
print ("<th>Lastname</th>");
print ("</tr>");
print ("<tr>");

foreach ($row as $key => $value)
print ("<td><input type ='text' value='$value' size = '30'></td>");

print ("</tr>");
print ("</table>");
}
}

print ("<table>");
print ("<tr>");
print ("<td>&nbsp;</td>");
print ("<td width='4%'>&nbsp;</td>");
print ("<td></tr>");

print ("<tr>");
print ("<td>&nbsp;</td>");
print ("<td width='4%'>&nbsp;</td>");

print ("<td><input type='submit' name='submit' value='Upgrade'></td>");
print ("</table></form>");

mysql_close($con);

?>

Mahabub

1:04 pm on Jan 2, 2009 (gmt 0)

10+ Year Member



Dear leenakrishnaa,

Ri8 now i am in confusion that multiple form could have a single submit button?

for ($counter == 0; $row = mysql_fetch_row($result); $counter++)
{
// build table to display result
print ("<form action='pp1.php' method='post'><h2><center>Member Profile</center></h2>"); // you generated individual form for the individual row of the table..
print ("<table border = '1' cellpadding = '3' cellspacing = '2' style = 'background-color: #ADD8E6'>");
print ("<tr>");
print ("<th>Firstname</th>");
print ("<th>Lastname</th>");
print ("</tr>");
print ("<tr>");

foreach ($row as $key => $value)
print ("<td><input type ='text' value='$value' size = '30'></td>");

print ("</tr>");
print ("</table>");
}
.
.
.

print ("<td><input type='submit' name='submit' value='Upgrade'></td>"); // you have just one submit

I think it will work for the last form only Though I am not sure..Also I want some one help in this purpose...

Thanks
Mahabub