Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<body>

<?php

$books_query=mysql_query("select * from labour");
$num_rows = mysql_num_rows($books_query);
while($books_rows=mysql_fetch_array($books_query)){


?>

<form method="post">
<table>
<tr>
<td><?php echo $books_rows['labour_id'] ; ?></td>
<td>in:</td><td><input type="text" name="l_in"></td>
<td>out:</td><td><input type="text" name="l_out"></td>
</tr>
</table>



<?php }?>
<td></td><td><input type="submit" name="submit" value="submt"/></td>
</form>

<?



if (isset($_POST['submit'])){

for($i=1; $i <= $num_rows; $i++) {

$lid=mysql_query("select labour_id from labour");



    $sql="INSERT INTO labour_attendance (emp_id,l_in,l_out) VALUES ('$lid','$_POST[l_in]','$_POST[l_out]')";
    $result = mysql_query($sql);
    if (!$result) {
     die('Invalid query: ' . mysql_error());
    }
}


}



?>
Posted
Comments
Mohibur Rashid 23-Jul-15 3:45am    
$lid=mysql_query("select labour_id from labour"); //here $lid is a resource
go to google and search "PHP mysql select" you will get lots of example.

try the query this way,
$sql="INSERT INTO labour_attendance (emp_id,l_in,l_out) VALUES ('".mysql_real_escape_string($lid)."','".mysql_real_escape_string($_POST["l_in"])."','".mysql_real_escape_string($_POST["l_out"])."')";

Also there is a lot you need to learn.
search on google about mysql_real_escape_string. learn about sql injection

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900