Wed Aug 17, 2011 6:11 am
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="emp"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
<?php
while($rows=mysql_fetch_array($result))
{
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="y" /></td>
<td align="center"><input name="empno[]" type="text" id="name" value="<? echo $rows['empno'];?>"></td>
<td align="center"><input name="empname[]" type="text" id="empname" value="<? echo $rows['empname'];?>"></td>
<td align="center"><input name="desig[]" type="text" id="desig" value="<? echo $rows['desig'];?>"></td>
</tr>
<?php
}
?>
<input type="submit" name="Submit" value="Submit">
<?php
// Get values from form
$no=$_POST['empno'];
$name=$_POST['empname'];
$desig=$_POST['desig'];
// Check if button name "Submit" is active, do this
if(array_key_exists('Submit', $_POST))
{
for($i=0;$i<count($count);$i++)
{
//protect form sql injection
$a = (int) $_POST['empno'][$i];
$b = mysql_real_escape_string( $_POST['empname'][$i] );
$c = mysql_real_escape_string( $_POST['desig'][$i] );
//read the query
$sql="INSERT INTO '$tbl_name' (empno, empname, desig) VALUES('{$a}', '{$b}', '{$c}')";
mysql_query($sql) or die(mysql_error());
}
}
Sat Aug 20, 2011 4:54 pm
Tue Dec 20, 2011 3:29 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.