| | |
please help. how do i add checkbox values in mysql row
![]() |
•
•
Join Date: Aug 2008
Posts: 18
Reputation:
Solved Threads: 0
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?
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 3:43 am.
•
•
Join Date: Aug 2008
Posts: 18
Reputation:
Solved Threads: 0
thank you!!! here's my code.
Display the Mysql Table and assign checkboxes for each value:
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.
Display the Mysql Table and assign checkboxes for each value:
PHP Syntax (Toggle Plain Text)
<html> <head> <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"> <link rel="icon" href="images/favicon.ico" type="image/x-icon"> <title>SM PORTAL WEBSITE</title> <meta http-equiv="Content-Type" content="text/html;"> <SCRIPT language=JavaScript> function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this[i] = makeArray.arguments[i]; } function getFullYear(d) { var y = d.getYear(); if (y < 1000) {y += 1900}; return y; } //var zone = "EDT"; var days = new makeArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); var months = new makeArray("January","February","March","April","May","June","July","August","September","October","November","December"); function format_time(t) { var Day = t.getDay(); var Date = t.getDate(); var Month = t.getMonth(); var Year = t.getFullYear(); timeString = ""; timeString += days[Day]; timeString += ", "; timeString += " "; timeString += months[Month]; timeString += " "; timeString += Date; timeString += ", "; timeString += " "; timeString += Year; return timeString; } </SCRIPT> <link rel="stylesheet" href="styles.css" type="text/css"> </head> <body bgcolor="#B49BCD" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#747AC6" vlink="#B49BCD"> <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"> <tr> <td valign="top" height="84" background="images/header_fill.jpg"><img src="images/smheaderlogo.jpg" width="321" height="84"></td> </tr> <tr> <td valign="top" height="22" background="images/blue_fill.gif" align="right"> <table width="220" border="0" cellspacing="0" cellpadding="0" height="22"> <tr> <td width="37"><img name="blue_crn" src="images/blue_crn.gif" width="37" height="22" border="0"></td> <td background="images/lt_blue_fill.gif" class="date" width="200"> <script language=JavaScript> <!-- d = new Date(); document.write(format_time(d)); // --> </script> </td> </tr> </table> </td> </tr> <tr> <td valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"> <tr> <td width="140" bgcolor="#92A2E1" valign="top" align="center"> <br> <table width="80%" height="228" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="links"><p><a href="home.htm"><img src="images/square.gif" width="7" height="7" border="0"></a> HOME<br> <br> <a href="http://10.101.4.21/nagios/"><img src="images/square.gif" width="7" height="7" border="0"></a> NAGIOS<br> <br> <a href="http://10.101.4.21/cgi-bin/smokeping.cgi"><img src="images/square.gif" width="7" height="7" border="0"></a> SMOKE PING <br> <br> <a href="http://10.101.160.59:9675/account/login"><img src="images/square.gif" width="7" height="7" border="0"></a> SPICEWORKS<br> <br> <a href="http://10.101.160.59:9675/helpdesk"><img src="images/square.gif" width="7" height="7" border="0"></a> HELP DESK <br> <br> <a href="humanresourcemanagement1.htm"><img src="images/square.gif" width="7" height="7" border="0"></a> HUMAN RESOURCE MANAGEMENT</p> <p><a href="memberlogin.php"><img src="images/square.gif" alt="df" width="7" height="7" border="0"></a> BLOG</p></td> </tr> </table> <p> </p></td> <td valign="top" bgcolor="#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="30" height="100%"> <tr> <td width="90%" valign="top" bgcolor="#FFFFFF" class="text"><p> </p> <p> </p> <?php //mysql connection $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "smportal"; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $query="SELECT * FROM employee"; // query on table $qry_result = mysql_query($query) or die(mysql_error()); $count = mysql_num_rows($qry_result); // count query result ?> <form method="post" action="addemptoproj.php"> <?php $display_string = "<table border='2' cellpadding='3'>"; $display_string .= "<tr>"; $display_string .= "<th>First Name</th>"; $display_string .= "<th>Last Name</th>"; $display_string .= "<th>Qualification</th>"; $display_string .= "<th>Add</th>"; //loop here while($row = mysql_fetch_array($qry_result)) { //inside while $display_string .= "<tr>"; $display_string .= "<td>$row[Fname]</td>"; $display_string .= "<td>$row[Lname]</td>"; $display_string .= "<td>$row[Qualification]</td>"; $display_string .= "<td><input type='checkbox' name='checkbox[]' id='checkbox[]' value='$row[empId]' /></td>"; $display_string .= "</tr>"; } $display_string .= "</table>"; $display_string .= "<table cellpadding='5' align='center'><td><input id='delete' type='submit' name='delete' value='Delete'/></td></table>"; echo $display_string; ?> </form> </td> <td width="10%" height="370" valign="top" bgcolor="#FFFFFF" class="text"> </td> </tr> </table> </td> </tr> <tr> <td width="140" bgcolor="#92A2E1" height="27"> </td> <td align="right" height="27" bgcolor="#FFFFFF"><img name="footer_right" src="images/footer_right.gif" width="110" height="27" border="0"></td> </tr> <tr> <td width="140" background="images/footer_fill.jpg" height="38"> </td> <td align="right" height="38" background="images/footer_fill.jpg"> <table width="100%" border="0" cellspacing="0" cellpadding="0" background="images/footer_fill.jpg"> <tr> <td valign="bottom" align="center" class="footer">Copyright © SM Mart Inc. All Rights Reserved.</td> <td align="right" width="110"><img name="footer_right2" src="images/footer_right2.gif" width="110" height="38" border="0"></td> </tr> </table> </td> </tr> <tr> <td width="140" height="10"> </td> <td align="right" height="10"> </td> </tr> </table> </td> </tr> </table> </body> </html>
PHP Syntax (Toggle Plain Text)
<?php # //mysql connection here //mysql connection $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "smportal"; //Connect to MySQL Server $dbconn=mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String # if($_POST['delete']) // from button name="delete" # { # $checkbox = $_POST['checkbox']; //from name="checkbox[]" # $countCheck = count($_POST['checkbox']); # # for($i=0;$i<$countCheck;$i++) # { # $del_id = $checkbox[$i]; # $sql = "SELECT * FROM employee WHERE empId=$del_id"; $result = mysql_query($sql, $dbconn); while($row = mysql_fetch_array($result)){ $sql3 = "SELECT hrmId, MAX(hrmId) FROM hrm1"; $sql2 = "INSERT INTO hrm1 (workingemp) VALUES ('{$row[Fname]}')"; mysql_query($sql2, $dbconn); mysql_query($sql3, $dbconn); } } # if($result) # { echo "SUCCESS"; } else { include("delete.php"); } } ?>
![]() |
Similar Threads
- inserting checkbox values in mysql +PHP (PHP)
- problem with my file upload (PHP)
- mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- Php newsletter error (PHP)
Other Threads in the PHP Forum
- Previous Thread: GoDaddy server timing out?
- Next Thread: hello every body
Views: 1196 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
access ajax apache archive array arrays beginner binary box broken buttons cakephp cart check checkbox class cms code curl database date delete development directory display download dropdown drupal dynamic echo email error file files form forms functions header href htaccess html image include insert ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql order output parse password paypal php problem query radio regex remote results script search security select server session sort source sql string syntax system table tutorial update updates upload url user validation validator variable video web website wordpress xml





