| | |
please help. how do i add checkbox values in mysql row
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
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 4: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
| Thread Tools | Search this Thread |
# .htaccess 5.2.10 access alexa apache api array beginner broken cakephp checkbox class clean clients cms code convert cron curl database date directory display dissertation dropdown dynamic echo$_get[x]changingitintovariable... email encode error fairness file folder form forms function functions google hack href htaccess html htmlspecialchars image include indentedsubcategory ip javascript joomla legislation limit link local login mail memberships menu methods multiple multipletables mysql mysqlquery network newsletters oop open passwords paypal pdf persist php provider query radio random redirect remote script search secure server sessions simple sockets source space spam sql system table tutorial upload url user variable video voteup web youtube





