mdvignesh Posted February 27, 2012 Share Posted February 27, 2012 how to store all txt box value and corresponding dates to DB <?php session_start(); if (!$_SESSION['uname']) { header("Location:login.php"); } ?> <html><head><title>Attendance sheet</title> <link rel="stylesheet" href="att_style.css" type="text/css" > <script src="datetimepicker.js"> </script> </head> <body> <form method="post" action=""> <label for="range_start">Start range:</label> <input name="from" id="frm_date" type="text"> <a href="javascript:NewCal('frm_date','ddmmyyyy')"><img src="cal.gif" alt="pick a date"></a> <label for="range_end">End range:</label> <input name="to" id="dpk" type="text" > <a href="javascript:NewCal('dpk','ddmmyyyy')"><img src="cal.gif" alt="pick a date"></a> <input name="date_but" type="submit" value="Go"> <a style="float:right" href="logout.php">Logout</a> </form> <br/><br/> <?php if (isset($_REQUEST['date_but'])) { //If go is clicked $fromDate = $_REQUEST['from']; $toDate = $_REQUEST['to']; $dateMonthYearArr = array(); $fromDateTS = strtotime($fromDate); $toDateTS = strtotime($toDate); $newdmy = array(); for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) { $currentDateStr = date("Y-m-d",$currentDateTS); $dateMonthYearArr[] = $currentDateStr; /* $newcurrDate = date("Y-m-d",$currentDateTS); $newdmy[] = $newcurrDate;*/ } //print_r($dateMonthYearArr); echo "No of days: " . count($dateMonthYearArr); //if() { ?> <form method="post" action="result.php"> <input name="hide_date" type="hidden" value="<?php print_r($dateMonthYearArr); ?>"/> <table border="1" cellspacing="0" cellpadding="2"> <tr> <th scope="row">DATE</th> <?php for ($i = 0; $i < 10; $i++) { if(!empty($dateMonthYearArr[$i])) { ?> <td align="center"> <?php print_r($dateMonthYearArr[$i]); ?> </td> <?php } } ?> </tr> <tr><th scope="row">IN</th> <?php for ($i = 0; $i < 10; $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><input name="in_time[]" id="in_time[]" type="text" size="5"></td> <?php } }?> </tr> <tr><th scope="row">OUT</th> <?php for ($i = 0; $i < 10; $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><input name="out_time[]" id="out_time[]" type="text" size="5"></td> <?php } }?> </tr> <tr><th scope="row">Late</th><?php for ($i = 0; $i < 10; $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><input name="late_time[]" id="late_time[]" type="text" size="5"></td> <?php } }?> </tr> </table> <?php //} ?> <br><br> <!-- second tab--> <?php if(count($dateMonthYearArr) >= 11) { ?> <table border="1" cellspacing="0" cellpadding="2"> <tr><th scope="row">DATE</th> <?php for ($i = 10; $i < 20; $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><?php print_r($dateMonthYearArr[$i]); ?></td> <?php } } ?> </tr> <tr><th scope="row">IN</th> <?php for ($i = 10; $i < 20; $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><input name="in_time2" id="in_time2" type="text" size="5"></td> <?php } }?> </tr> <tr><th scope="row">OUT</th> <?php for ($i = 10; $i < 20; $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><input name="out_time2" type="text" size="5"></td> <?php } }?> </tr> <tr><th scope="row">Late</th> <?php for ($i = 10; $i < 20; $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><input name="late_time2" type="text" size="5"></td> <?php } }?> </tr> </table> <?php } ?> <br/><br/> <!-- Third table--> <?php if(count($dateMonthYearArr) > 21) { ?> <table border="1" cellspacing="0" cellpadding="2"> <tr> <th scope="row">DATE</th> <?php for ($i = 20; $i < count($dateMonthYearArr); $i++) { if(!empty($dateMonthYearArr[$i])) {?> <td align="center"><?php print_r($dateMonthYearArr[$i]); ?></td><?php } }?> </tr> <tr><th scope="row">IN</th> <?php for ($i = 20; $i < count($dateMonthYearArr); $i++) { if(!empty($dateMonthYearArr[$i])) { }?> <td align="center"><input name="in_time3" type="text" size="5"></td> <?php } ?> </tr> <tr><th scope="row">OUT</th> <?php for ($i = 20; $i < count($dateMonthYearArr); $i++) { ?> <td align="center"><input name="out_time3" type="text" size="5"></td> <?php } ?> </tr> <tr><th scope="row">Late</th> <?php for ($i = 20; $i < count($dateMonthYearArr); $i++) { ?> <td align="center"><input name="late_time3" type="text" size="5"></td> <?php } ?> </tr> </table> <?php } ?> <br><br> <p align="center"><input name="sub" type="submit" value="Save"></p> </form> <?php } ?> </body> </html> result.php <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php session_start(); if (!$_SESSION['uname']) { header("Location:login.php"); } require("connect.php"); $in_time[] = mysql_real_escape_string(implode(" ",$_POST['in_time'])); $out_time[] = mysql_real_escape_string(implode(" ",$_POST['out_time'])); echo "In time: "; print_r($in_time); echo "<br>"."out time: "; print_r($out_time); $curdate = $_POST['hide_date']; print_r($curdate); foreach($curdate as $key=>$val) { print_r($val); } $ins = mysql_query("INSERT INTO timetable VALUES ('', '".$_SESSION['uname']."', '".$val."', '".$in_time."', '".$out_time."', '') "); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/257856-all-array-value-to-db/ Share on other sites More sharing options...
batwimp Posted February 27, 2012 Share Posted February 27, 2012 You should call session_start() before outputting anything to the browser. Just FYI. Quote Link to comment https://forums.phpfreaks.com/topic/257856-all-array-value-to-db/#findComment-1321683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.