943,859 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1566
  • PHP RSS
Aug 27th, 2008
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
fortiz147 is offline Offline
18 posts
since Aug 2008
Aug 27th, 2008
1

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

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
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
phpuser is offline Offline
55 posts
since May 2008
Aug 27th, 2008
0

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

thank you!!! here's my code.

Display the Mysql Table and assign checkboxes for each value:
PHP Syntax (Toggle Plain Text)
  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.
PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 11
Solved Threads: 0
Newbie Poster
fortiz147 is offline Offline
18 posts
since Aug 2008
Aug 28th, 2008
0

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

hello everyone,,i new in php...

plz tell me about getting page id,,\

how can i get a apecifuc page id..\\
Reputation Points: 10
Solved Threads: 1
Newbie Poster
ahmadjhoney is offline Offline
9 posts
since Aug 2008
Sep 23rd, 2010
0
Re: please help. how do i add checkbox values in mysql row
Hi,fortiz147

here as per your pasted code first of all there is no connection between your new inserted data and employee id i mean your $sql2 and $sql3 on line number 41,42 are totally independent.

Your coding is right for insert Data in table but still if you cant find new entry in table "hrm1" then you can do echo $sql2 and can run query direct in Phpmyadmin sql section so can get idea wheres the problem.

Best luck..
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
phpuser is offline Offline
55 posts
since May 2008
Sep 23rd, 2010
0
Re: please help. how do i add checkbox values in mysql row
I doubt he is still looking for help with this two years later.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: search engine problems
Next Thread in PHP Forum Timeline: ';' Problem in mailto.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC