sniperscope Posted December 21, 2008 Share Posted December 21, 2008 Hi all gurus. Last 4 days i am searching through internet and last 2 days whole forum of phpfreaks. i am currently building (actually trying) an admin page which let the admin decide who is going to work today and from what time to what time. So far i could able to do get the data from db and print it but i can not update with multiple selection. here is my working.php <?php virtual('/Connections/del.php'); ?> <?php mysql_select_db($db_del, $del); $query_r = "SELECT * FROM shukkin ORDER BY id ASC"; $r = mysql_query($query_r, $del) or die(mysql_error()); $row_r = mysql_fetch_assoc($r); $totalRows_r = mysql_num_rows($r); ?> ... <body> <form name="form1" method="POST" action="shukkin_update.php"> <table width="563" border="1"> <tr> <th width="65">Working today ?</th> <th width="124">name</th> <th width="293" align="center">From~End</th> <th width="53">ask to admin</th> </tr> <?php do { ?> <tr> <td align="center"><input name="is_working" type="checkbox" <?php if ($row_r['is_working']=="Y"){ echo " checked=\"checked\" value=\"N\""; } else { echo "value=\"Y\""; } ?>/> </td> <td align="center"> <input type="hidden" name="name" value="<?php echo $row_r['name'];?>" /> <?php echo $row_r['name']; ?> </td> <td align="center"><select name="start_time_hour"> <option value="00">00</option> <option value="01">01</option> <option value="02">02</option> ....... </select> : <select name="start_time_min"> <option value="00">00</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> </select> ~ <select name="finish_time_hour"> <option value="00">00</option> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> : <select name="finish_time_min"> <option value="00">00</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> </select> </td> <td align="center"><input type="checkbox" name="ask_to_admin" <?php if($row_r['flag']=="N"){ echo " value=\"N\""; } else { echo " value=\"Y\""; } ?> /> </td> </tr> <?php } while ($row_r = mysql_fetch_assoc($r)); ?> <?php while(mysql_fetch_assoc($r));?> <tr> <td> </td> <td> </td> <td> </td> <td><div align="right"> <input type="submit" name="button" value="Submit" /></div></td> </tr> </table> </form> </body> </html> <?php mysql_free_result($r); ?> So far this works great if i dont repeat table and it is perfectly working with single data but i want to make all records at one time to (because there is more than 100 ppl working and it takes time to update one by one) choose who is going to work today by checking "Is Work" column and decide what time to what time will work by choosing "drop down menu". If i click the "ask To admin" check box which means time not decided yet so ask to admin. I am seriously desperate and i dont know what to do and how to do. Hopefully i made myself clear. Any help will return thousands of thousands thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 21, 2008 Share Posted December 21, 2008 I think I am understanding your problem. What you need to do is set an ID value (or whatever is the unique value for your records) for all of the fields so the processing page knows what record to update. I would do it as arrays. Then the processing page just needs to loop through the checkbox array for the is_working to determine which ones to update. I also made a couple minor changes to clean up the code and make it more readable. <?php virtual('/Connections/del.php') mysql_select_db($db_del, $del); $query_r = "SELECT * FROM shukkin ORDER BY id ASC"; $r = mysql_query($query_r, $del) or die(mysql_error()); $row_r = mysql_fetch_assoc($r); $totalRows_r = mysql_num_rows($r); ?> ... <body> <form name="form1" method="POST" action="shukkin_update.php"> <table width="563" border="1"> <tr> <th width="65">Working today ?</th> <th width="124">name</th> <th width="293" align="center">From~End</th> <th width="53">ask to admin</th> </tr> <?php do { if ($row_r['is_working']=="Y"){ $is_working_value = " checked=\"checked\" value=\"N\""; } else { $is_working_value = "value=\"Y\""; } if($row_r['flag']=="N"){ $ask_to_admin_value = " value=\"N\""; } else { $ask_to_admin_value = " value=\"Y\""; } ?> <tr> <td align="center"><input name="is_working[{$row_r['id']}]" type="checkbox" <?php echo $is_working_value;?> /> </td> <td align="center"> <input type="hidden" name="name[{$row_r['id']}]" value="<?php echo $row_r['name'];?>" /> <?php echo $row_r['name']; ?> </td> <td align="center"> <select name="start_time_hour[{$row_r['id']}]"> <option value="00">00</option> <option value="01">01</option> <option value="02">02</option> ....... </select> : <select name="start_time_min[{$row_r['id']}]"> <option value="00">00</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> </select> ~ <select name="finish_time_hour[{$row_r['id']}]"> <option value="00">00</option> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> : <select name="finish_time_min[{$row_r['id']}]"> <option value="00">00</option> <option value="10">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> </select> </td> <td align="center"> <input type="checkbox" name="ask_to_admin[{$row_r['id']}]" <?php echo $ask_to_admin_value;?> /> </td> </tr> <?php } while ($row_r = mysql_fetch_assoc($r)); while(mysql_fetch_assoc($r)); ?> <tr> <td> </td> <td> </td> <td> </td> <td><div align="right"> <input type="submit" name="button" value="Submit" /></div></td> </tr> </table> </form> </body> </html> <?php mysql_free_result($r); ?> Quote Link to comment Share on other sites More sharing options...
sniperscope Posted December 21, 2008 Author Share Posted December 21, 2008 Dear mjdamato; I really rally thank you for your rapid response. I tried your code, but this time i got "array array array array " in next page. if i dont check the "ask to admin" checkbox then i got error says "undefined index." when try to update it then i got "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '//finish_time_min='Array', is_working='Array', flag='' WHERE nick_name='Array'' at line 1" message. What do you suggest ? Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 22, 2008 Share Posted December 22, 2008 Well, your processing code will need to be modified for the new code since all of the POST values will be sent as arrays. Post that code for more help. Quote Link to comment Share on other sites More sharing options...
sniperscope Posted December 22, 2008 Author Share Posted December 22, 2008 Well, your processing code will need to be modified for the new code since all of the POST values will be sent as arrays. Post that code for more help. Dear mjdamato sorry for late reply, i had to go out of city for one day. here is my process code. I build it with dw cs3. For me it must work good but unfortunately mysql does not listen my words. Dont tell me i know i mess up. :'( :'( <?php virtual('/Connections/del.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "update")) { $updateSQL = sprintf("UPDATE shukkin SET start_time_hour=%s, start_time_min=%s, finish_time_hour=%s, finish_time_min=%s, is_working=%s, flag=%s WHERE nick_name=%s", GetSQLValueString($_POST['tart_hour'], "text"), GetSQLValueString($_POST['start_min'], "text"), GetSQLValueString($_POST['finish_hour'], "text"), GetSQLValueString($_POST['finish_min'], "text"), GetSQLValueString(isset($_POST['is_working']) ? "true" : "", "defined","'Y'","'N'"), GetSQLValueString(isset($_POST['flag']) ? "true" : "", "defined","'Y'","'N'"), GetSQLValueString($_POST['name'], "text")); mysql_select_db($database_del, $del); $Result1 = mysql_query($updateSQL, $del) or die(mysql_error()); $updateGoTo = "shukkin.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } mysql_select_db($database_del, $del); $query_db_update = "SELECT * FROM shukkin ORDER BY id ASC"; $db_update = mysql_query($query_db_update, $del) or die(mysql_error()); $row_db_update = mysql_fetch_assoc($db_update); $totalRows_db_update = mysql_num_rows($db_update); $name = $_POST['name']; $is_working = $_POST['is_working']; $start_hour = $_POST['start_time_hour']; $start_min = $_POST['start_time_min']; $finish_hour = $_POST['finish_time_hour']; $finish_min = $_POST['finish_time_min']; $flag = $_POST['flag']; ?> <form action="<?php echo $editFormAction; ?>" method="POST" name="update"> <table width="500" border="0"> <tr> <td> <input type="hidden" name="id" value="<?php echo $row_db_update['id']; ?>" /> <input type="hidden" name="is_working" value="<?php echo $row_db_update['is_working']; ?>" /> <input type="hidden" name="name" value="<?php echo $row_db_update['name']; ?>" /> <input type="hidden" name="start_hour" value="<?php echo $row_db_update['start_time_hour']; ?>" /> <input type="hidden" name="start_min" value="<?php echo $row_db_update['start_time_min']; ?>" /> <input type="hidden" name="finish_hour" value="<?php echo $row_db_update['finish_time_hour']; ?>" /> <input type="hidden" name="finish_min" value="<?php echo $row_db_update['finish_time_min']; ?>" /> <input type="hidden" name="flag" value="" /> </td> </tr> </table> <input type="hidden" name="MM_update" value="update" /> </form> <?php mysql_free_result($db_update); ?> Quote Link to comment Share on other sites More sharing options...
sniperscope Posted December 22, 2008 Author Share Posted December 22, 2008 guys, please give an idea. Where do i have to start ? or what should i do ? Quote Link to comment 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.