nithan Posted July 23, 2012 Share Posted July 23, 2012 I have a form which displays name and a text field after fetching names from the database in an array: <input id='<? echo $name; ?>' type='text' name='students[<? echo $name; ?>]' disabled="disabled"/> Example: Name and TextField. When I want to insert it in database, I can't insert. Following is the code that I am using. Am I doing right thing? $marks= $_POST['students']; $marksn = array_filter($marks); foreach($marksn as $name=>$vals){ trim($vals) !== ''; $query="INSERT INTO attend (Name, Training, Date, Attendance, Marks) VALUES ('$name','$trainings','$today','$val','$vals')"; $result=mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/ Share on other sites More sharing options...
g__ink Posted July 23, 2012 Share Posted July 23, 2012 OK so straight up without seeing any of your code, you are going to get nothing in your $_POST array as your text fields are all disabled. If you would like further help, please post your form code as well as the code you are using to process the $_POST array. Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363656 Share on other sites More sharing options...
mikhl Posted July 23, 2012 Share Posted July 23, 2012 If you want to send a value with a disabled text field you have to set something to the value attribute. <input type="text" name="name" id="id" value="some value" /> Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363659 Share on other sites More sharing options...
peipst9lker Posted July 23, 2012 Share Posted July 23, 2012 Keep in mind that u can easily edit disabled input-fields with Firebug or some other plugin! Another way would be to just modify the POST-data sent to the script. Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363663 Share on other sites More sharing options...
nithan Posted July 23, 2012 Author Share Posted July 23, 2012 OK so straight up without seeing any of your code, you are going to get nothing in your $_POST array as your text fields are all disabled. If you would like further help, please post your form code as well as the code you are using to process the $_POST array. ----------------------------------------- Thank you. This is the code that I am using: I am very new to PHP. Please correct me if I am wrong. This is my Form code: <style type="text/css"> table.hovertable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #999999; border-collapse: collapse; } table.hovertable th { background-color:#c3dde0; border-width: 1px; padding: 8px; border-style: solid; border-color: #a9c6c9; } table.hovertable tr { background-color:#d4e3e5; } table.hovertable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #a9c6c9; } table.hovertable { width: 30%; text-align: center; font: 14px Verdana, Arial, Helvetica, sans-serif; } tr.yellow td { border-top: 1px solid #FB7A31; border-bottom: 1px solid #FB7A31; background: #FFC; font: 20px Verdana, Arial, Helvetica, sans-serif; } </style> <script> function confirmDelete(delUrl) { if (confirm("Are you sure you want to delete")) { document.location = delUrl; } } </script> <script type="text/javascript"> function enableText(checkBool, textID) { textFldObj = document.getElementById(textID); //Disable the text field textFldObj.disabled = !checkBool; //Clear value in the text field if (!checkBool) { textFldObj.value = ''; } } </script> <html> <body> <? include("attendrop.php"); ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label class="form-label-left" id="label_4" for="input_4">Select Training: </label> <div id="cid_4" class="form-input"> <select class="form-dropdown" style="width:150px" id="input_4" name="training"> <OPTION VALUE=0>Choose <?=$optionsa?> </SELECT> <input type="submit" name="submit" value="Mark Attendance"><br> </form> <?php if(isset($_POST['submit'])) $training= $_POST['training']; { ?> <div align="center"> Mark Attendance for <font color="red"> <? echo $training; ?> </font>Training. <form method="post" action="attendinsert.php" > <input type="hidden" value="<? echo $training; ?>" name="training" /> <table class="hovertable" align="center" width="30%" cellpadding="50" > <tr class="yellow"> <tr> <td><font face="Arial, Helvetica, sans-serif">Name</font></td> <td><font face="Arial, Helvetica, sans-serif">OSS ID</font></td> <td><font face="Arial, Helvetica, sans-serif">Mark Attendance</font></td> <td><font face="Arial, Helvetica, sans-serif">Marks</font></td> <?php include("database.php"); $training= $_POST['training']; $from= $_POST['from']; $to= $_POST['to']; $tablename="agentstable"; $query="SELECT * FROM agentstable ORDER BY name ASC"; $result=mysql_query($query); $num=mysql_numrows($result); $options=""; $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $name=mysql_result($result,$i,"name"); $empcode=mysql_result($result,$i,"emp_code"); $oss=mysql_result($result,$i,"oss_username"); $emails=mysql_result($result,$i,"emailaddress"); ?> <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';"> <td><? echo $name; ?></td><td><? echo $oss; ?></td><td> <input id="myCheckBox" type='checkbox' onclick="enableText(this.checked, '<? echo $name; ?>');" name='student[<? echo $name; ?>]' value='1' /> </td><td> <input id='<? echo $name; ?>' type='text' name='students[<? echo $name; ?>]' disabled="disabled"/></td> </tr> <?php $i++; } ?> </table> <input type='submit' value='Submit' name='submit_button' /> </form> </div> <? } ?> </div> </body> </html> This code is to insert: <?php include("database.php"); $tablename="agentstable"; date_default_timezone_set('Asia/Calcutta'); $format = 'm/d/Y'; $today = date ( $format ); if(!isset($_POST['submit_button'])){ //form has not been submitted return; } //form HAS been submitted $student_array = $_POST['student']; $trainings = $_POST['training']; $marks= $_POST['students']; $marksn = array_filter($marks); /*foreach($marks as $marks=>$vals){ } */ foreach($student_array as $name=>$val){ $val = ($val == "1")?1:0; if($val == 1) { //$val needs to be 0 or 1. foreach($marksn as $name=>$vals){ trim($vals) !== ''; $query="INSERT INTO attend (Name, Training, Date, Attendance, Marks) VALUES ('$name','$trainings','$today','$val','$vals')"; $result=mysql_query($query); } } if($result){ echo("<br>Input data is succeed"); echo "<a href='attendanceform.php'>Back to Attendance Page</a>"; } else { echo("<br>Input data is fail"); } } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363665 Share on other sites More sharing options...
peipst9lker Posted July 23, 2012 Share Posted July 23, 2012 Put your code into code-BBtags (remove the spaces inside the brackets!) e.g [ code] YOUR CODE HERE [ /code] [ php] YOUR PHP CODE HERE [ /php] Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363666 Share on other sites More sharing options...
g__ink Posted July 23, 2012 Share Posted July 23, 2012 Im sorry but if you are sending data via a standard html form then this If you want to send a value with a disabled text field you have to set something to the value attribute. <input type="text" name="name" id="id" value="some value" /> is incorrect. As per http://www.w3schools.com/tags/att_input_disabled.asp Disabled <input> elements in a form will not be submitted. Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363667 Share on other sites More sharing options...
mikhl Posted July 23, 2012 Share Posted July 23, 2012 also properly indenting your code ensures that you can see mistakes ans makes it 100% better for others to read and understand your code. Making it easy for others makes it easy for you. Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363668 Share on other sites More sharing options...
mikhl Posted July 23, 2012 Share Posted July 23, 2012 Im sorry but if you are sending data via a standard html form then this If you want to send a value with a disabled text field you have to set something to the value attribute. <input type="text" name="name" id="id" value="some value" /> is incorrect. As per http://www.w3schools.com/tags/att_input_disabled.asp Disabled <input> elements in a form will not be submitted. My bad Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363669 Share on other sites More sharing options...
mikhl Posted July 23, 2012 Share Posted July 23, 2012 You could use hidden input types. Although, as previously stated, the values are easily editable by someone who knows what they are doing. Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363670 Share on other sites More sharing options...
PaulRyan Posted July 23, 2012 Share Posted July 23, 2012 You could always use the attribute readonly for example: <input type="text" name="test" readonly="readonly" value="TESTER"> Quote Link to comment https://forums.phpfreaks.com/topic/266111-inserting-conents-which-are-submitted-in-an-array/#findComment-1363692 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.