Array values for validation

Thread Solved

Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Array values for validation

 
0
  #1
Feb 21st, 2008
Good day all!
I have been working on a project that requires me to to the following:
Select a user from a list, on submit go to next page.
The next page contains the session variable $id of the selected user.
On this page, I am assigning menu permissions. I have a repeating row from a recordset and I am getting the values for insertion or update from the form correctly on insert/update, but I can't seem to get the select box "menuassignment[]" to show the users input on error checking. I think it has something to do with how I am going about getting the array values, but have not been able to get it to work.
Here is the code for the page:
  1. /////////////////////////////
  2. $expected = array('menuassignment');
  3.  
  4. $missing = array();
  5. // assume that there is nothing suspect
  6. $suspect = false;
  7. /////////////////////////////////////
  8.  
  9. $AddData="no";
  10. $warnstart="no";
  11. $MM_flag="MM_insert";
  12. if((isset($_POST["Submit"])) && ($_POST["MM_insert"] == "access1")) {
  13. $AddData="yes";
  14. $warnstart="no";
  15. if (!$_POST['restrict'])
  16. {
  17. $AddData = "no";
  18. ?>
  19. <?php
  20. if ($warnstart=="no") { ?>
  21. <div class="warningstart">Please complete the missing item(s) indicated. </div>
  22. <?php
  23. }
  24. $warnstart="yes";
  25. if (!$_POST['restrict']) { ?> <div class="warning"><li>Please set the Restrict Record Edit Options</li></div>
  26. <?php }
  27. }
  28. for($i=0;$i<count($_POST['menuname']);$i++)
  29. {
  30. $assigned=$_POST['menuassignment'][$i];
  31. $MName=$_POST['menuname'][$i];
  32. $id=$_SESSION['mambo_user_id'];
  33. ///echo out error message
  34. if ($assigned =="")
  35. {
  36. $AddData = "no";
  37. if ($warnstart=="no")
  38. { ?>
  39. <div class="warningstart">Please complete the missing item(s) indicated. </div>
  40. <?php
  41. }
  42. $warnstart="yes";?>
  43. <div class="warning"><li>Please set the Menu Assignment Options for <? echo $MName; ?> Menu</li></div>
  44. <?php //}
  45. }
  46. }
  47. if ($warnstart=="yes")
  48. { ?>
  49. <div class="warningend"></div>
  50. <?php
  51. }
  52. }
  53.  
  54. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  55. {
  56. $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  57.  
  58. switch ($theType) {
  59. case "text":
  60. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  61. break;
  62. case "long":
  63. case "int":
  64. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  65. break;
  66. case "double":
  67. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  68. break;
  69. case "date":
  70. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  71. break;
  72. case "defined":
  73. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  74. break;
  75. }
  76. return $theValue;
  77. }
  78. if((isset($_POST["Submit"])) && ($_POST["MM_insert"] == "access1") && $AddData=="yes" && isset($_POST['menuname']))
  79. {
  80.  
  81. $updateApps= sprintf("UPDATE `skills_access` SET `restrict`=%s WHERE `mambo_user_id`=%s AND `skills_access_id`=%s ",
  82. GetSQLValueString($restrict, "text"),
  83. GetSQLValueString($mambo_user_id, "text"),
  84. GetSQLValueString($AccessID, "text"));
  85.  
  86. mysql_select_db($database_training, $training);
  87. $result2 = mysql_query($updateApps, $training) or die(mysql_error());
  88.  
  89. if((isset($_POST['menuname']))|| (isset($_POST['menuassignment']))|| (isset($_POST['id']))|| (isset($_POST['username'])))
  90. {
  91. for($i=0;$i<count($_POST['menuname']);$i++)
  92. {
  93. $assigned=$_POST['menuassignment'][$i];
  94. $MName=$_POST['menuname'][$i];
  95. //$id=$_POST['mambo_user_id'];
  96. $menu=$_POST['menu'][$i];
  97. $username = $row_rsUser['username'];
  98. //insert statement goes here
  99. $insertApps = "INSERT INTO assignedmenu(`username`, `mambo_user_id`, `Access`, `menuname`, `MenuID`) VALUES('$username', '$id', '$assigned','$MName', $menu)";
  100. $result1 = mysql_query($insertApps) or die(mysql_error());
  101. }
  102. }
  103. ///////////////////////
  104. if ($suspect) {
  105. //$mailSent = false;
  106. unset($missing);
  107. }
  108. else {
  109. // process the $_POST variables
  110. foreach ($_POST as $key => $value) {
  111. // assign to temporary variable and strip whitespace if not an array
  112. $temp = is_array($value) ? $value : trim($value);
  113. // if empty and required, add to $missing array
  114. if (empty($temp) && in_array($key, $required)) {
  115. array_push($missing, $key);
  116. }
  117. // otherwise, assign to a variable of the same name as $key
  118. elseif (in_array($key, $expected)) {
  119. ${$key} = $temp;
  120. }
  121. }
  122. }
  123.  
  124.  
  125. if (!$suspect && empty($missing)) {
  126. // set default values for variables that might not exist
  127.  
  128. $menuassignment = isset($menuassignment) ? $menuassignment : array('None selected');
  129. }
  130. ///////////////////////////
  131. // here put the insertgoto page
  132. //$insertGoTo = "access2.php";
  133. //header(sprintf("Location: %s", $insertGoTo));
  134. }
  135. ?>
  136. Here is the form:
  137. <? $_SESSION['AccessID']; ?>
  138. <form id="access1" name="access1" method="POST" >
  139.  
  140. <table width="550" border="1" bordercolor="#000066">
  141. <tr>
  142. <td colspan="2" scope="row"><div align="center"><strong>Training Database Menu Security &amp; Restrict Record Edit </strong></div></td>
  143. </tr>
  144. <tr>
  145. <td colspan="2" scope="row"><div align="left"><b>
  146. <?php echo $row_rsUser['username']; ?>
  147. <input name="username" type="hidden" value="<? echo $row_rsUser['username'] ; ?>" />
  148. <input name="id[]" type="hidden" value="<? echo $_SESSION['mambo_user_id']; ?>">
  149. <input name="skill_access_id" type="hidden" value="<? echo $_SESSION['AccessID']; ?>" />
  150. </div></td>
  151. </tr>
  152. <tr>
  153. <td width="218" valign="middle" scope="row"><? echo $var; ?></td>
  154. <td width="316" valign="middle" scope="row">Restrict Record Edit?
  155. <?php
  156. // initialize or capture variable
  157. $XX = !isset($_POST['restrict'])? NULL : $_POST['restrict'];
  158. ?>
  159. <select name="restrict">
  160. <option value="<?php echo $XX;?>" SELECTED><?php echo $XX;?></option>
  161. <option value="Yes">Yes</option>
  162. <option value="No">No</option>
  163. </select>
  164. </td>
  165. </tr>
  166. <tr>
  167. <td height="46" colspan="2" valign="middle" scope="row"><div align="center"><span class="style1"><em>Please indicate which menus the user will have access to</em>. </span></div></td>
  168. </tr>
  169. </table>
  170. <table width="550" border="1" bordercolor="#00066">
  171.  
  172. <?php do { ?>
  173. <tr>
  174. <td width="227" valign="middle" scope="row"><B>
  175. <input name="menu[]" type="hidden" id="menu[]" value="<?php echo $row_rsMenu['MenuID']; ?>" />
  176. <?php echo $row_rsMenu['menuname']; ?>
  177. <input name="menuname[]" type="hidden" value="<? echo $row_rsMenu['menuname'] ; ?>" />
  178. </B></td>
  179. <td>
  180. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  181. as you can see by the commented out code, I have tried to get this to work on several ways. All I want to do here is :
  182. if the user hits submit and has not filled out the form properly, I want the users initial selected values retained for output to the screen.
  183.  
  184. ///////////////////////////////////////////////////////////////////////////////////////////////////
  185. <? //for($i=2;$i<count($_POST['menu']);$i++)
  186. //{
  187. //$menuassignment= array();
  188. //foreach ($menuassignment as $item)
  189. //{
  190. //echo "the values of menuassignment are '".$item."'<br/>";
  191. //}
  192. //$menuassignment=$_POST['menuassignment'][$i]; ?>
  193. <select name="menuassignment[]">
  194. <option value=""
  195. <?php
  196. $OK = isset($_POST['menuassignment']) ? true : false;
  197. if ($OK && isset($missing) && in_array('', $_POST['menuassignment'])) { ?>
  198. selected="selected"
  199. <?php } ?>></option>
  200. <option value="Yes"<?php if ($OK && isset($missing) && in_array('Yes', $_POST['menuassignment'])) { ?>
  201. selected="selected"<?php } ?>>Yes</option>
  202. <option value="No"<?php if ($OK && isset($missing) && in_array('No', $_POST['menuassignment'])) { ?>selected="selected"<?php } ?>>No</option>
  203. </select>
  204. <? //} ?>
  205. </tr>
  206. <?php } while ($row_rsMenu = mysql_fetch_assoc($rsMenu)); ?>
  207. <tr>
  208. <td colspan="2" valign="middle" scope="row"><div align="center">
  209. <input name="Submit" type="Submit" id="Submit" value="Submit" />
  210. &nbsp;&nbsp;<input type="button" name="Cancel" value="Return to Access Menu" onClick="self.location='index.php'" />
  211. </div></td>
  212. </tr>
  213. <? //} ?>
  214. </table>
  215. <input type="hidden" name="MM_insert" value="access1">
  216. </form>
  217. <pre>
  218. <?php
  219. if ($_POST) { print_r($_POST); }
  220. ?>
  221. </pre>
  222. </body>
  223. </html>
  224. <?php
  225. mysql_free_result($rsApps);
  226. mysql_free_result($rsUser);
  227. mysql_free_result($rsAppName);
  228. mysql_free_result($rsMenu);
  229. //mysql_free_result($rsYN);
  230. mysql_free_result($rsRestrict);
  231.  
  232. mysql_free_result($rsAccess);
  233. //ob_flush();
  234. ?>

If any one can help get me going in the right direction here, I would greatly appreciate it.
I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Array values for validation

 
0
  #2
Feb 21st, 2008
What is this $expected = array('menuassignment'); for ? Where are you using it ? What is the array you are trying to validate ? Could you explain your problem in detail ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: Array values for validation

 
0
  #3
Feb 21st, 2008
please forgive me, I should have clarified myslef and code a bit better.

the question about
$expected = array('menuassignment');
This resides in a part of the error checking as shown below. I was attempting to capture the array variables there.


if ($suspect) {
//$mailSent = false;
unset($missing);
}
else {
// process the $_POST variables
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key, $required)) {
array_push($missing, $key);
}
// otherwise, assign to a variable of the same name as $key
elseif (in_array($key, $expected)) {
${$key} = $temp;
}
}
}



All I want to do is get the users initial input redisplayed in the form on error check.
Ex.
If selected "Yes" to have access to the "Admin" menu, and didn't complete the rest of the form, the form will the be redisplayed with information on what items are missing/incomplete. It is at this point that I would want the users selection of "Yes" to the Admin menu to be retained on the form.
The select menuassignment[] is where I need to get the values redisplayed.
Thanks for any help!
I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Array values for validation

 
0
  #4
Feb 21st, 2008
umm.. is menuassignment an array and are you trying to assign that array to $expected ? Sorry for my ignorance, but I still don't get it. What is the problem exactly ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: Array values for validation

 
0
  #5
Feb 21st, 2008
menuassignment is an array for insert/update

<select name="menuassignment[]">
<option value=""
<?php
$OK = isset($_POST['menuassignment']) ? true : false;
if ($OK && isset($missing) && in_array('', $_POST['menuassignment'])) { ?>
selected="selected"
<?php } ?>></option>
<option value="Yes"<?php if ($OK && isset($missing) && in_array('Yes', $_POST['menuassignment'])) { ?>
selected="selected"<?php } ?>>Yes</option>
<option value="No"<?php if ($OK && isset($missing) && in_array('No', $_POST['menuassignment'])) { ?>selected="selected"<?php } ?>>No</option>
</select>


the array assigned for insert/update is

if((isset($_POST['menuname']))|| (isset($_POST['menuassignment']))|| (isset($_POST['id']))|| (isset($_POST['username'])))
{
for($i=0;$i<count($_POST['menuname']);$i++)
{
$assigned=$_POST['menuassignment'][$i];
$MName=$_POST['menuname'][$i];
//$id=$_POST['mambo_user_id'];
$menu=$_POST['menu'][$i];
$username = $row_rsUser['username'];
//insert statement goes here
$insertApps = "INSERT INTO assignedmenu(`username`, `mambo_user_id`, `Access`, `menuname`, `MenuID`) VALUES('$username', '$id', '$assigned','$MName', $menu)";
$result1 = mysql_query($insertApps) or die(mysql_error());
}
}



in the select menuassignment[] (shown above this text) I was trying to retain the values the user selected for error checking to display back to the form.
I have tried several ways to get this accomplished, but I just can't seem to get it to work. Perhaps the coding in the select menuassignment[] options is incorrect?
I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: Array values for validation

 
0
  #6
Feb 22nd, 2008
I have a form that contains a repeating region that allows an admin to set permissions on menus. I have a select box named "menuassignmnets[]" that I am displaying the options of "", "Yes" or "No".
I have been able to insert/ update everything fine and now I am on to error validation.
I have tried numerous ways to be able to "retain" the values the user selected initially, but have not been sucessful.
i can see by using the
  1. <pre>
  2. <?php
  3. if ($_POST) { print_r($_POST); }
  4. ?>
  5. </pre>
that my array values are correct for insertion, but I need the users selected values to be "shown" in the select box if the form cannot be submitted due to error validation.

I know there are severeal things commented out within the code I have posted but I left them there for reminding what I have already tried for my testing purposes.
Any help would be greatly appreciated.
Jeni
I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: Array values for validation

 
0
  #7
Feb 27th, 2008
I have been able to sort all this out. If anyone is interested, please let me know and I will post he code.
I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Array values for validation

 
0
  #8
Feb 27th, 2008
Yep. Sure.. How did you do it ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: Array values for validation

 
0
  #9
Feb 27th, 2008
OK...here it is in all it's "Glory"
  1. <?php require_once('../Connections/training.php'); ?>
  2. <?php require_once('../Connections/mambo.php'); ?>
  3. <?
  4. error_reporting(E_ALL ^ E_NOTICE);
  5. session_start();
  6.  
  7. $id=$_SESSION['mambo_user_id'];
  8. $AccessID=$_SESSION['AccessID'];
  9. $AppName= $_SESSION['web_app_id'];
  10. mysql_select_db($database_training, $training);
  11. $query_rsApps = "SELECT * FROM skills_access WHERE mambo_user_id = '$id'";
  12. $rsApps = mysql_query($query_rsApps, $training) or die(mysql_error());
  13. $row_rsApps = mysql_fetch_assoc($rsApps);
  14. $totalRows_rsApps = mysql_num_rows($rsApps);
  15.  
  16. mysql_select_db($database_mambo, $mambo);
  17. $query_rsUser = "SELECT * FROM mos_corpusers WHERE id = '$id'";
  18. $rsUser = mysql_query($query_rsUser, $mambo) or die(mysql_error());
  19. $row_rsUser = mysql_fetch_assoc($rsUser);
  20. $totalRows_rsUser = mysql_num_rows($rsUser);
  21.  
  22. mysql_select_db($database_training, $training);
  23. $query_rsAppName = "SELECT * FROM web_access_applications WHERE web_app_id = '$AppName' ";
  24. $rsAppName = mysql_query($query_rsAppName, $training) or die(mysql_error());
  25. $row_rsAppName = mysql_fetch_assoc($rsAppName);
  26. $totalRows_rsAppName = mysql_num_rows($rsAppName);
  27. $var= $row_rsAppName['app_description'];
  28. mysql_select_db($database_training, $training);
  29. $query_rsMenu = "SELECT * FROM menu";
  30. $rsMenu = mysql_query($query_rsMenu, $training) or die(mysql_error());
  31. $row_rsMenu = mysql_fetch_assoc($rsMenu);
  32. $totalRows_rsMenu = mysql_num_rows($rsMenu);
  33.  
  34. mysql_select_db($database_mambo, $mambo);
  35. $query_rsYN = "SELECT * FROM yn";
  36. $rsYN = mysql_query($query_rsYN, $mambo) or die(mysql_error());
  37. $row_rsYN = mysql_fetch_assoc($rsYN);
  38. $totalRows_rsYN = mysql_num_rows($rsYN);
  39.  
  40. mysql_select_db($database_training, $training);
  41. $query_rsRestrict = "SELECT * FROM skills_access WHERE mambo_user_id = '$id' AND skills_access_id = '$AccessID' ";
  42. //$query_rsRestrict = "SELECT * FROM skills_access WHERE web_app_id ='40' AND mambo_user_id= '$MUID'";
  43.  
  44. $rsRestrict = mysql_query($query_rsRestrict, $training) or die(mysql_error());
  45. $row_rsRestrict = mysql_fetch_assoc($rsRestrict);
  46. $totalRows_rsRestrict = mysql_num_rows($rsRestrict);
  47.  
  48. mysql_select_db($database_mambo, $mambo);
  49. $query_rsAccess = "SELECT * FROM assignedmenu WHERE mambo_user_id = '$id' ";
  50. $rsAccess = mysql_query($query_rsAccess, $mambo) or die(mysql_error());
  51. $row_rsAccess = mysql_fetch_assoc($rsAccess);
  52. $totalRows_rsAccess = mysql_num_rows($rsAccess);
  53. //validation
  54. //validate the proper form fields have been entered
  55. $AddData="no";
  56. $warnstart="no";
  57. $MM_flag="MM_insert";
  58. if((isset($_POST["Submit"])) && ($_POST["MM_insert"] == "access1"))
  59. {
  60. $AddData="yes";
  61. $warnstart="no";
  62. if (!$_POST['restrict'])
  63. {
  64. $AddData = "no";
  65. ?>
  66. <?php
  67.  
  68. if ($warnstart=="no")
  69. { ?>
  70. <div class="warningstart">Please complete the missing item(s) indicated. </div>
  71. <?php
  72. }
  73. $warnstart="yes";
  74. if (!$_POST['restrict']) { ?> <div class="warning"><li>Please set the Restrict Record Edit Options</li></div>
  75. <?php }
  76. }
  77. foreach($_POST['menuassignment'] as $row=> $assigned)
  78. {
  79. $assigned= $assigned;
  80. $id=$_SESSION['mambo_user_id'];
  81. $username = $row_rsUser['username'];
  82. $menu=$_POST['menu'][$row];
  83. $MenuID = $_POST['menu'][$row];
  84. $MName=$_POST['menuname'][$row];
  85. ///echo out error message
  86. if ($assigned =="")
  87. {
  88. $AddData = "no";
  89. if ($warnstart=="no")
  90. { ?>
  91. <div class="warningstart">Please complete the missing item(s) indicated. </div>
  92. <?php } $warnstart="yes";?>
  93. <div class="warning"><li>Please set the Menu Assignment Options for <? echo $MName; ?> Menu</li></div>
  94. <?php }
  95. }
  96. if ($warnstart=="yes")
  97. { ?><div class="warningend"></div>
  98. <?php }
  99. }
  100. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  101. {
  102. $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  103.  
  104. switch ($theType) {
  105. case "text":
  106. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  107. break;
  108. case "long":
  109. case "int":
  110. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  111. break;
  112. case "double":
  113. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  114. break;
  115. case "date":
  116. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  117. break;
  118. case "defined":
  119. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  120. break;
  121. }
  122. return $theValue;
  123. }
  124. if((isset($_POST["Submit"])) && ($_POST["MM_insert"] == "access1") && $AddData=="yes" )
  125. {
  126. $updateApps= sprintf("UPDATE `skills_access` SET `restrict`=%s WHERE `mambo_user_id`=%s AND `web_app_id`=%s",
  127. GetSQLValueString($restrict, "text"),
  128. GetSQLValueString($mambo_user_id, "text"),
  129. GetSQLValueString($web_app_id, "int"));
  130.  
  131. mysql_select_db($database_training, $training);
  132. $result2 = mysql_query($updateApps, $training) or die(mysql_error());
  133.  
  134. //echo $updateApps;
  135. if((isset($_POST['menu']))|| (isset($_POST['menuassignment']))|| (isset($_POST['id']))|| (isset($_POST['username'])))
  136. {
  137.  
  138. foreach($_POST['menuassignment'] as $row=> $assigned){
  139. $assigned= $assigned;
  140. $id=$_SESSION['mambo_user_id'];
  141. $username = $row_rsUser['username'];
  142. $menu=$_POST['menu'][$row];
  143. $MenuID = $_POST['menu'][$row];
  144. $MName=$_POST['menuname'][$row];
  145.  
  146. $insertApps = "INSERT INTO assignedmenu(`username`, `mambo_user_id`, `Access`, `menuname`, `MenuID`) VALUES('".$username."', '".$id."', '".$assigned."','".$MName."', '".$menu."')";
  147. $result1 = mysql_query($insertApps) or die(mysql_error());
  148. }
  149. }
  150. ///////////////////////////
  151. // here put the insertgoto page
  152. $insertGoTo = "access2.php";
  153. header(sprintf("Location: %s", $insertGoTo));
  154. }
  155. ?>
  156. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  157. <html xmlns="http://www.w3.org/1999/xhtml">
  158. <head>
  159. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  160. <title>Assign Restricted Access - Training Module</title>
  161. <style type="text/css">
  162. <!--
  163. .style1 {color: #FF0000}
  164. .warning {
  165. background-color: #ffffee;
  166. color: #660000;
  167. width: 650px;
  168. padding: 5px;
  169. border-right-width: thin;
  170. border-left-width: thin;
  171. border-right-style: solid;
  172. border-left-style: solid;
  173. border-right-color: #FF0000;
  174. border-left-color: #FF0000;
  175. text-indent: 20px;
  176. }
  177. .warningend {
  178. background-color: #ffffee;
  179. color: #660000;
  180. width: 650px;
  181. padding: 5px;
  182. border-right-width: thin;
  183. border-left-width: thin;
  184. border-right-style: solid;
  185. border-left-style: solid;
  186. border-right-color: #FF0000;
  187. border-left-color: #FF0000;
  188. border-bottom-width: thin;
  189. border-bottom-style: solid;
  190. border-bottom-color: #FF0000;
  191. }
  192. .warningstart {
  193. background-color: #ffffee;
  194. color: #660000;
  195. width: 650px;
  196. padding: 5px;
  197. border-right-width: thin;
  198. border-left-width: thin;
  199. border-right-style: solid;
  200. border-left-style: solid;
  201. border-right-color: #FF0000;
  202. border-left-color: #FF0000;
  203. border-top-width: thin;
  204. border-top-style: solid;
  205. border-top-color: #FF0000;
  206. }
  207. .notify {
  208. border: 1px solid #336699;
  209. background-color: #ffffee;
  210. color: #336699;
  211. width: 650px;
  212. padding: 5px;
  213. }
  214. -->
  215. </style>
  216. <style type="text/css">
  217. <!--
  218. body,td,th {
  219. font-family: Verdana, Arial, Helvetica, sans-serif;
  220. font-size: 12px;
  221. color: #000066;
  222. }
  223. .style1 {font-weight: bold}
  224. -->
  225. </style>
  226. </head>
  227. <body>
  228. <? $_SESSION['AccessID']; ?>
  229. <form id="access1" name="access1" method="POST" >
  230. <? $AppName= $_SESSION['web_app_id'];?>
  231. <table width="550" border="1" bordercolor="#000066">
  232. <tr>
  233. <td colspan="2" scope="row"><div align="center"><strong>Training Database Menu Security &amp; Restrict Record Edit </strong></div></td>
  234. </tr>
  235. <tr>
  236. <td colspan="2" scope="row"><div align="left"><b>
  237. <?php echo $row_rsUser['username']; ?>
  238. <input name="web_app_id" type="hidden" id="web_app_id" value="<? echo $AppName; ?>" />
  239. <input name="username" type="hidden" value="<? echo $row_rsUser['username'] ; ?>" />
  240. <input name="id[]" type="hidden" value="<? echo $_SESSION['mambo_user_id']; ?>">
  241. <input name="skill_access_id" type="hidden" value="<? echo $_SESSION['AccessID']; ?>" /><? //echo $_SESSION['AccessID']; ?>
  242. </div></td>
  243. </tr>
  244. <tr>
  245. <td width="218" valign="middle" scope="row"><? echo $var; ?></td>
  246. <td width="316" valign="middle" scope="row">Restrict Record Edit?
  247.  
  248. <?php
  249. // initialize or capture variable
  250. $XX = !isset($_POST['restrict'])? NULL : $_POST['restrict'];
  251. ?>
  252. <select name="restrict">
  253. <option value="<?php echo $XX;?>" SELECTED><?php echo $XX;?></option>
  254. <option value="Yes">Yes</option>
  255. <option value="No">No</option>
  256. </select>
  257.  
  258. </td>
  259. </tr>
  260. <tr>
  261. <td height="46" colspan="2" valign="middle" scope="row"><div align="center"><span class="style1"><em>Please indicate which menus the user will have access to</em>. </span></div></td>
  262. </tr>
  263. </table>
  264. <table width="550" border="1" bordercolor="#00066">
  265.  
  266. <?php do { ?>
  267. <tr>
  268. <td width="227" valign="middle" scope="row"><B>
  269. <input name="menu[<?php echo $row_rsMenu['MenuID']; ?>]" type="hidden" id="menu" value="<?php echo $row_rsMenu['MenuID']; ?>" />
  270. <?php echo $row_rsMenu['menuname']; ?>
  271. <input name="menuname[<?php echo $row_rsMenu['MenuID']; ?>]" type="hidden" value="<? echo $row_rsMenu['menuname'] ; ?>" />
  272. </B></td>
  273. <td>
  274. <select name="menuassignment[<?php echo $row_rsMenu['MenuID']; ?>]" id="menuassignment<?php echo $row_rsMenu['MenuID']; ?>">
  275. <option value=""<?php if(!isset($_POST['menuassignment'][$row_rsMenu['MenuID']]) || $_POST['menuassignment'][$row_rsMenu['MenuID']] == ""){ ?> selected="selected"<?php } ?>></option>
  276. <option value="Yes"<?php if(isset($_POST['menuassignment'][$row_rsMenu['MenuID']]) && $_POST['menuassignment'][$row_rsMenu['MenuID']] == "Yes"){ ?>selected="selected"<?php } ?>>Yes</option>
  277. <option value="No"<?php if(isset($_POST['menuassignment'][$row_rsMenu['MenuID']]) && $_POST['menuassignment'][$row_rsMenu['MenuID']] == "No"){ ?>selected="selected"<?php } ?>>No</option>
  278. </select>
  279. </tr>
  280. <?php } while ($row_rsMenu = mysql_fetch_assoc($rsMenu)); ?>
  281. <tr>
  282. <td colspan="2" valign="middle" scope="row"><div align="center">
  283. <input name="Submit" type="Submit" id="Submit" value="Submit" />
  284. &nbsp;&nbsp;<input type="button" name="Cancel" value="Return to Access Menu" onClick="self.location='index.php'" />
  285. </div></td>
  286. </tr>
  287. </table>
  288. <input type="hidden" name="MM_insert" value="access1">
  289. </form>
  290. <pre>
  291. <?php
  292. //if ($_POST) { print_r($_POST); }
  293. ?>
  294. </pre>
  295. </body>
  296. </html>
  297. <?php
  298. mysql_free_result($rsApps);
  299. mysql_free_result($rsUser);
  300. mysql_free_result($rsAppName);
  301. mysql_free_result($rsMenu);
  302. mysql_free_result($rsYN);
  303. mysql_free_result($rsRestrict);
  304. mysql_free_result($rsAccess);
  305. ?>
I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Array values for validation

 
0
  #10
Feb 27th, 2008
lil complicated script, this one !
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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