please help. how do i add checkbox values in mysql row

Reply

Join Date: Aug 2008
Posts: 18
Reputation: fortiz147 is an unknown quantity at this point 
Solved Threads: 0
fortiz147 fortiz147 is offline Offline
Newbie Poster

please help. how do i add checkbox values in mysql row

 
0
  #1
Aug 27th, 2008
here's the process:
1. i display the mysql data in rows with checkboxes on each row
2. i want to add the checked values into another table under the specific field employee

here's the problem: i can't seem to insert the checked value to the specified project table.
what if i had different projects in that table, how will the query know that i want to insert that specific employee to the project table?
Last edited by fortiz147; Aug 27th, 2008 at 4:43 am.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 14
Reputation: phpuser is an unknown quantity at this point 
Solved Threads: 1
phpuser phpuser is offline Offline
Newbie Poster

Re: please help. how do i add checkbox values in mysql row

 
1
  #2
Aug 27th, 2008
hi,may be i help you.i understand little what you want but if you paste your code here then it will be useful for me
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 18
Reputation: fortiz147 is an unknown quantity at this point 
Solved Threads: 0
fortiz147 fortiz147 is offline Offline
Newbie Poster

Re: please help. how do i add checkbox values in mysql row

 
0
  #3
Aug 27th, 2008
thank you!!! here's my code.

Display the Mysql Table and assign checkboxes for each value:
  1. <html>
  2. <head>
  3. <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
  4. <link rel="icon" href="images/favicon.ico" type="image/x-icon">
  5.  
  6.  
  7. <title>SM PORTAL WEBSITE</title>
  8.  
  9. <meta http-equiv="Content-Type" content="text/html;">
  10. <SCRIPT language=JavaScript>
  11. function makeArray() {
  12. for (i = 0; i<makeArray.arguments.length; i++)
  13. this[i] = makeArray.arguments[i];
  14. }
  15.  
  16. function getFullYear(d) {
  17. var y = d.getYear();
  18. if (y < 1000) {y += 1900};
  19. return y;
  20. }
  21.  
  22. //var zone = "EDT";
  23. var days = new makeArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  24. var months = new makeArray("January","February","March","April","May","June","July","August","September","October","November","December");
  25.  
  26. function format_time(t) {
  27.  
  28. var Day = t.getDay();
  29. var Date = t.getDate();
  30. var Month = t.getMonth();
  31. var Year = t.getFullYear();
  32.  
  33. timeString = "";
  34. timeString += days[Day];
  35. timeString += ", ";
  36. timeString += " ";
  37. timeString += months[Month];
  38. timeString += " ";
  39. timeString += Date;
  40. timeString += ", ";
  41. timeString += " ";
  42. timeString += Year;
  43.  
  44. return timeString;
  45. }
  46. </SCRIPT>
  47. <link rel="stylesheet" href="styles.css" type="text/css">
  48. </head>
  49. <body bgcolor="#B49BCD" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#747AC6" vlink="#B49BCD">
  50. <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  51. <tr>
  52. <td valign="top" height="84" background="images/header_fill.jpg"><img src="images/smheaderlogo.jpg" width="321" height="84"></td>
  53. </tr>
  54. <tr>
  55. <td valign="top" height="22" background="images/blue_fill.gif" align="right">
  56. <table width="220" border="0" cellspacing="0" cellpadding="0" height="22">
  57. <tr>
  58. <td width="37"><img name="blue_crn" src="images/blue_crn.gif" width="37" height="22" border="0"></td>
  59. <td background="images/lt_blue_fill.gif" class="date" width="200">
  60. <script language=JavaScript>
  61. <!--
  62. d = new Date();
  63. document.write(format_time(d));
  64. // -->
  65. </script>
  66. </td>
  67. </tr>
  68. </table>
  69. </td>
  70. </tr>
  71. <tr>
  72. <td valign="top">
  73. <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  74. <tr>
  75. <td width="140" bgcolor="#92A2E1" valign="top" align="center"> <br>
  76. <table width="80%" height="228" border="0" cellpadding="0" cellspacing="0">
  77. <tr>
  78. <td class="links"><p><a href="home.htm"><img src="images/square.gif" width="7" height="7" border="0"></a> HOME<br>
  79. <br>
  80. <a href="http://10.101.4.21/nagios/"><img src="images/square.gif" width="7" height="7" border="0"></a> NAGIOS<br>
  81. <br>
  82. <a href="http://10.101.4.21/cgi-bin/smokeping.cgi"><img src="images/square.gif" width="7" height="7" border="0"></a> SMOKE
  83. PING <br>
  84. <br>
  85. <a href="http://10.101.160.59:9675/account/login"><img src="images/square.gif" width="7" height="7" border="0"></a> SPICEWORKS<br>
  86. <br>
  87. <a href="http://10.101.160.59:9675/helpdesk"><img src="images/square.gif" width="7" height="7" border="0"></a> HELP
  88. DESK <br>
  89. <br>
  90. <a href="humanresourcemanagement1.htm"><img src="images/square.gif" width="7" height="7" border="0"></a> HUMAN
  91. RESOURCE MANAGEMENT</p>
  92. <p><a href="memberlogin.php"><img src="images/square.gif" alt="df" width="7" height="7" border="0"></a> BLOG</p></td>
  93. </tr>
  94. </table>
  95. <p>&nbsp;</p></td>
  96. <td valign="top" bgcolor="#FFFFFF">
  97. <table width="100%" border="0" cellspacing="0" cellpadding="30" height="100%">
  98. <tr>
  99. <td width="90%" valign="top" bgcolor="#FFFFFF" class="text"><p>&nbsp;</p>
  100. <p>&nbsp;</p>
  101.  
  102.  
  103.  
  104.  
  105.  
  106. <?php
  107.  
  108. //mysql connection
  109. $dbhost = "localhost";
  110. $dbuser = "root";
  111. $dbpass = "";
  112. $dbname = "smportal";
  113.  
  114.  
  115. //Connect to MySQL Server
  116. mysql_connect($dbhost, $dbuser, $dbpass);
  117. //Select Database
  118. mysql_select_db($dbname) or die(mysql_error());
  119. // Retrieve data from Query String
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. $query="SELECT * FROM employee"; // query on table
  127. $qry_result = mysql_query($query) or die(mysql_error());
  128.  
  129.  
  130. $count = mysql_num_rows($qry_result); // count query result
  131.  
  132.  
  133.  
  134. ?>
  135.  
  136.  
  137. <form method="post" action="addemptoproj.php">
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. <?php
  146. $display_string = "<table border='2' cellpadding='3'>";
  147. $display_string .= "<tr>";
  148. $display_string .= "<th>First Name</th>";
  149. $display_string .= "<th>Last Name</th>";
  150. $display_string .= "<th>Qualification</th>";
  151. $display_string .= "<th>Add</th>";
  152. //loop here
  153.  
  154. while($row = mysql_fetch_array($qry_result))
  155.  
  156. {
  157.  
  158. //inside while
  159.  
  160. $display_string .= "<tr>";
  161. $display_string .= "<td>$row[Fname]</td>";
  162. $display_string .= "<td>$row[Lname]</td>";
  163. $display_string .= "<td>$row[Qualification]</td>";
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. $display_string .= "<td><input type='checkbox' name='checkbox[]' id='checkbox[]' value='$row[empId]' /></td>";
  171.  
  172.  
  173.  
  174. $display_string .= "</tr>";
  175. }
  176.  
  177. $display_string .= "</table>";
  178. $display_string .= "<table cellpadding='5' align='center'><td><input id='delete' type='submit' name='delete' value='Delete'/></td></table>";
  179.  
  180. echo $display_string;
  181.  
  182. ?>
  183.  
  184.  
  185.  
  186. </form>
  187.  
  188.  
  189.  
  190.  
  191.  
  192. </td>
  193. <td width="10%" height="370" valign="top" bgcolor="#FFFFFF" class="text">&nbsp;</td>
  194. </tr>
  195. </table>
  196. </td>
  197. </tr>
  198. <tr>
  199. <td width="140" bgcolor="#92A2E1" height="27">&nbsp;</td>
  200. <td align="right" height="27" bgcolor="#FFFFFF"><img name="footer_right" src="images/footer_right.gif" width="110" height="27" border="0"></td>
  201. </tr>
  202. <tr>
  203. <td width="140" background="images/footer_fill.jpg" height="38">&nbsp;</td>
  204. <td align="right" height="38" background="images/footer_fill.jpg">
  205. <table width="100%" border="0" cellspacing="0" cellpadding="0" background="images/footer_fill.jpg">
  206. <tr>
  207. <td valign="bottom" align="center" class="footer">Copyright &copy;
  208. SM Mart Inc. All Rights Reserved.</td>
  209. <td align="right" width="110"><img name="footer_right2" src="images/footer_right2.gif" width="110" height="38" border="0"></td>
  210. </tr>
  211. </table>
  212. </td>
  213. </tr>
  214. <tr>
  215. <td width="140" height="10">&nbsp;</td>
  216. <td align="right" height="10">&nbsp;</td>
  217. </tr>
  218. </table>
  219. </td>
  220. </tr>
  221. </table>
  222. </body>
  223. </html>
This code is suppose to add the checked values to the latest/maximum empId which is autogenerated in the specified field,employee, in table hrm1.
  1. <?php
  2. #
  3. //mysql connection here
  4.  
  5. //mysql connection
  6. $dbhost = "localhost";
  7. $dbuser = "root";
  8. $dbpass = "";
  9. $dbname = "smportal";
  10.  
  11.  
  12. //Connect to MySQL Server
  13. $dbconn=mysql_connect($dbhost, $dbuser, $dbpass);
  14. //Select Database
  15. mysql_select_db($dbname) or die(mysql_error());
  16. // Retrieve data from Query String
  17.  
  18. #
  19. if($_POST['delete']) // from button name="delete"
  20. #
  21. {
  22. #
  23. $checkbox = $_POST['checkbox']; //from name="checkbox[]"
  24. #
  25. $countCheck = count($_POST['checkbox']);
  26. #
  27.  
  28. #
  29. for($i=0;$i<$countCheck;$i++)
  30. #
  31. {
  32. #
  33. $del_id = $checkbox[$i];
  34. #
  35.  
  36. $sql = "SELECT * FROM employee WHERE empId=$del_id";
  37.  
  38. $result = mysql_query($sql, $dbconn);
  39.  
  40. while($row = mysql_fetch_array($result)){
  41. $sql3 = "SELECT hrmId, MAX(hrmId) FROM hrm1";
  42. $sql2 = "INSERT INTO hrm1 (workingemp) VALUES ('{$row[Fname]}')";
  43. mysql_query($sql2, $dbconn);
  44. mysql_query($sql3, $dbconn);
  45. }
  46.  
  47.  
  48.  
  49. }
  50. #
  51. if($result)
  52. #
  53. {
  54.  
  55. echo "SUCCESS";
  56.  
  57. }
  58.  
  59. else
  60.  
  61. {
  62. include("delete.php");
  63.  
  64. }
  65.  
  66. }
  67.  
  68. ?>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 4
Reputation: ahmadjhoney is an unknown quantity at this point 
Solved Threads: 1
ahmadjhoney ahmadjhoney is offline Offline
Newbie Poster

Re: please help. how do i add checkbox values in mysql row

 
0
  #4
Aug 28th, 2008
hello everyone,,i new in php...

plz tell me about getting page id,,\

how can i get a apecifuc page id..\\
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC