Afficher un message
Vieux 12/04/2008, 10h05   #8
bangsundara@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Updateing a SQL select populated form

Thanks Jerry,

Thank you very muvh for your advise. you are a great teacher.

Here is the code for populate and display check box data with check/d.
and also i attaching a sample for update.
display works ok.
but the updated fails as i am not getting (POST) proper values to
update all are blank.
can you advise me some with some more hint.
Thanks in Advance.

---------------
display:tdisplay.php it works ok
---------------------------------
<?php
$host="localhost"; // Host name.
$dbuser="***"; // MySQL username.
$dbpassword="***"; // MySQL password.
$database="test"; // Database name.
mysql_connect($host,$dbuser,$dbpassword) or die('Unable to connect to
thye database');
mysql_select_db($database) or die("Unable to select database");
$result = mysql_query("SELECT * FROM tblsales ORDER BY slno,empid");
$i = 0;
print "<form name='namestoupdate' method='post'
action='tblupdaten.php'>\n";

while ($rec = mysql_fetch_array($result)) {
print "<input type='hidden' name='slno[$i]'
value='{$rec['slno']}' />";
print "<tr>";
print "<p> {$rec['slno']} {$rec['empid']} {$rec['empname']}
{$rec['salesamt']} ";
$checked = (($rec['flg'] ==1)?"CHECKED":"");
print " <input type=\"checkbox\" NAME=\"flg[]\" VALUE=\"flg\"
$checked/> ";
print "<input type='text' size='25' name='rec[$i]'
value='{$rec['date']}' /></p> ";
++$i;
}
print "</table>";
print "<p><input type='submit' value='Update' /></p>";
print "</form>";
mysql_close();
?>
-----------------------------------------

Now for the update:tblupdaten.php
it fails get proper values in the arry all are blanks
----------------------------------------------
<?php
$host="localhost"; // Host name.
$dbuser="***"; // MySQL username.
$dbpassword=""; // MySQL password.
$database="test"; // Database name.
mysql_connect($host,$dbuser,$dbpassword) or die('Unable to connect to
thye database');
mysql_select_db($database) or die("Unable to select database");
$size = count($_POST['slno']);
$i = 0;
while ($i < $size)
{
$slno= $_POST['slno'][$i];//echo "slno=$slno";
$empid= $_POST['empid'][$i];echo "empid=$empid";
$flg= $_POST['flg'][$i];echo "flg=$flg";
$sdate= $_POST['date'][$i];echo "date=$date";
$id = $_POST['id'][$i];$query = "UPDATE tblsales SET date = \"$sdate\"
WHERE id = \"$id\" and slno = \"$slno\" LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
print "$empid<br /><br /><em>Updated!</em><br /><br />";
++$i;
}
mysql_close();
?>
------------------------------------------------------------

-evolu
  Réponse avec citation
 
Page generated in 0,08061 seconds with 9 queries