473,324 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Fill List/Menu box

Slaxer13
106 64KB
Hi guys,

I want to know how to fill a list/menu box with the column: "id_utilizador" from table: "tbl_utilizadores" from database: "db_faq".

And when i select a id on that box i want it to fill the fields, which are ("utilizador", "email", "password", "administrator").

This page is a update page for admin use only (that is taken care of).

This is the update page code (atualizar_registo.php):

Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/FAQ.php'); ?>
  2. <?php
  3. if (!isset($_SESSION)) {
  4.   session_start();
  5. }
  6. $MM_authorizedUsers = "1";
  7. $MM_donotCheckaccess = "false";
  8.  
  9. // *** Restrict Access To Page: Grant or deny access to this page
  10. function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  11.   // For security, start by assuming the visitor is NOT authorized. 
  12.   $isValid = False; 
  13.  
  14.   // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  15.   // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  16.   if (!empty($UserName)) { 
  17.     // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
  18.     // Parse the strings into arrays. 
  19.     $arrUsers = Explode(",", $strUsers); 
  20.     $arrGroups = Explode(",", $strGroups); 
  21.     if (in_array($UserName, $arrUsers)) { 
  22.       $isValid = true; 
  23.     } 
  24.     // Or, you may restrict access to only certain users based on their username. 
  25.     if (in_array($UserGroup, $arrGroups)) { 
  26.       $isValid = true; 
  27.     } 
  28.     if (($strUsers == "") && false) { 
  29.       $isValid = true; 
  30.     } 
  31.   } 
  32.   return $isValid; 
  33. }
  34.  
  35. $MM_restrictGoTo = "login_errado.php";
  36. if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  37.   $MM_qsChar = "?";
  38.   $MM_referrer = $_SERVER['PHP_SELF'];
  39.   if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  40.   if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  41.   $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  42.   $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  43.   header("Location: ". $MM_restrictGoTo); 
  44.   exit;
  45. }
  46. ?>
  47. <?php
  48. if (!function_exists("GetSQLValueString")) {
  49. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  50. {
  51.   if (PHP_VERSION < 6) {
  52.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  53.   }
  54.  
  55.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  56.  
  57.   switch ($theType) {
  58.     case "text":
  59.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  60.       break;    
  61.     case "long":
  62.     case "int":
  63.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  64.       break;
  65.     case "double":
  66.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  67.       break;
  68.     case "date":
  69.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  70.       break;
  71.     case "defined":
  72.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  73.       break;
  74.   }
  75.   return $theValue;
  76. }
  77. }
  78.  
  79. $editFormAction = $_SERVER['PHP_SELF'];
  80. if (isset($_SERVER['QUERY_STRING'])) {
  81.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  82. }
  83.  
  84. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  85.   $updateSQL = sprintf("UPDATE tbl_utilizadores SET utilizador=%s, password=%s, email=%s WHERE id_utilizador=%s",
  86.                        GetSQLValueString($_POST['utilizador'], "text"),
  87.                        GetSQLValueString($_POST['password'], "text"),
  88.                        GetSQLValueString($_POST['email'], "text"),
  89.                        GetSQLValueString($_POST['id_utilizador'], "int"));
  90.  
  91.   mysql_select_db($database_FAQ, $FAQ);
  92.   $Result1 = mysql_query($updateSQL, $FAQ) or die(mysql_error());
  93.  
  94.   $updateGoTo = "login.php";
  95.   if (isset($_SERVER['QUERY_STRING'])) {
  96.     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
  97.     $updateGoTo .= $_SERVER['QUERY_STRING'];
  98.   }
  99.   header(sprintf("Location: %s", $updateGoTo));
  100. }
  101.  
  102. $colname_Utilizadores = "-1";
  103. if (isset($_GET['id_utilizador'])) {
  104.   $colname_Utilizadores = $_GET['id_utilizador'];
  105. }
  106. mysql_select_db($database_FAQ, $FAQ);
  107. $query_Utilizadores = sprintf("SELECT * FROM tbl_utilizadores WHERE id_utilizador = %s", GetSQLValueString($colname_Utilizadores, "int"));
  108. $Utilizadores = mysql_query($query_Utilizadores, $FAQ) or die(mysql_error());
  109. $row_Utilizadores = mysql_fetch_assoc($Utilizadores);
  110. $totalRows_Utilizadores = mysql_num_rows($Utilizadores);
  111. ?>
  112. <!doctype html>
  113. <html>
  114. <head>
  115. <meta charset="utf-8">
  116. <title>Atualizar Registo</title>
  117. </head>
  118.  
  119. <body>
  120. <h1>Atualizar Registo</h1>
  121. <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  122.   <table align="center">
  123.     <tr valign="baseline">
  124.       <td nowrap align="right">ID:</td>
  125.       <td></td>
  126.     </tr>
  127.     <tr valign="baseline">
  128.       <td nowrap align="right">Utilizador:</td>
  129.       <td><input type="text" name="utilizador" value="<?php echo htmlentities($row_Utilizadores['utilizador'], ENT_COMPAT, 'utf-8'); ?>" size="32"></td>
  130.     </tr>
  131.     <tr valign="baseline">
  132.       <td nowrap align="right">Password:</td>
  133.       <td><input type="text" name="password" value="<?php echo htmlentities($row_Utilizadores['password'], ENT_COMPAT, 'utf-8'); ?>" size="32"></td>
  134.     </tr>
  135.     <tr valign="baseline">
  136.       <td nowrap align="right">Email:</td>
  137.       <td><input type="text" name="email" value="<?php echo htmlentities($row_Utilizadores['email'], ENT_COMPAT, 'utf-8'); ?>" size="32"></td>
  138.     </tr>
  139.     <tr valign="baseline">
  140.       <td nowrap align="right">Admin:</td>
  141.       <td><input type="text" name="administrator" value="<?php echo htmlentities($row_Utilizadores['administrator'], ENT_COMPAT, 'utf-8'); ?>" size="32"></td>
  142.     </tr>
  143.     <tr valign="baseline">
  144.       <td nowrap align="right">&nbsp;</td>
  145.       <td><input type="submit" value="Atualizar Registo"></td>
  146.     </tr>
  147.   </table>
  148.   <input type="hidden" name="MM_update" value="form1">
  149.   <input type="hidden" name="id_utilizador" value="<?php echo $row_Utilizadores['id_utilizador']; ?>">
  150. </form>
  151. <p>&nbsp;</p>
  152. </body>
  153. </html>
  154. <?php
  155. mysql_free_result($Utilizadores);
  156. ?>
  157.  
There is an image attached with the page and where the box should be.

Any additional info needed just ask.

Thanks in advance.
Peace,
Slaxer13

PS: Some things may be in portuguese, if you don't understand just let me know...
Attached Images
File Type: jpg Untitled.jpg (18.3 KB, 62 views)
Jun 1 '15 #1
1 1247
Slaxer13
106 64KB
So i managed to make my listbox show the records...

Expand|Select|Wrap|Line Numbers
  1.         <select name="select" class="textfields" id="ddl_id">
  2.             <option id="0">-- Selecione o ID --</option>
  3.             <?php
  4.                 require("dbconfig.php");
  5.                 $get_ids = mysql_query("SELECT * FROM tbl_utilizadores");
  6.                 while($vertodos = mysql_fetch_array($get_ids)){    
  7.             ?>
  8.             <option id="<?php echo $vertodos['id_utilizador'];?>"><?php echo $vertodos['utilizador'] ?></option>
  9.             <?php } ?>
  10.       </select>
How do i populate the form based on the record i choose in the list box?
Jun 1 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ali poursadri | last post by:
Hi, I want to fill my list box from a dataset in c#. I use adapter and fill command and bind it to a listbox, but it is very slow for large data about 500000 records. How can I view this list...
4
by: Brian | last post by:
How can I use javascript to select Items in a List/Menu? For example: (value1, value2) will select value1 and value2 in a list menu....
4
by: fizzyfozzy | last post by:
Hi, I am trying to figure out how to show or hide a selection of divs on my page depending on what is selected from a list/menu item, using css & javascript. I have tried to use the script...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
4
by: jmartmem | last post by:
Greetings, I have an ASP page containing a Record Insertion Form with a number of fields (mostly text fields and list/menu fields) linked to an Access database. I've created an onsubmit behavior...
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
5
by: jmartmem | last post by:
Greetings, I am using Dreamweaver CS3 to design an ASP page that contains an Insert Record Form. Within this form are two list/menu form fields that I would like to "synchronize". In other words,...
1
by: Mala7 | last post by:
Hi I have two list/menu - to be specific they are car Brand menu & car model menu - in my page, what i need to do is to: - make the car model menu dimmed at the start - when a selection made to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.