Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Ricardo_Coelho

Recuperar valor de "Select(Liste/Menu)" em formulár

Recommended Posts

Estou tentando fazer um formulário de alteração e queria uma forma de recuperar o valor de Select(Liste/Menu).

 

quero q o Select(Liste/Menu) exiba a opção selecionada anteriormente.

 

Ex de formulario:

 

 

<div id="cliente">
<h2>Cadastrar Cliente</h2>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <p>
    <label for="login">Login:   </label>
    <input type="text" name="login" id="login" />
  </p>
  <p>
    <label for="senha">Senha:  </label>
    <input type="password" name="senha" id="senha" />
  </p>
  <p>
    <label for="nivel">Sistema:</label>
    <select name="nivel" id="nivel">
      <option value="Senior-Rubi-4W">Senior-Rubi-4W</option>
      <option value="Senior-Windows">Senior-Windows</option>
      <option value="WK-Sistemas">WK-Sistemas</option>
      <option value="Bloqueado">Bloqueado</option>
      <option selected="selected">Escolha o Sistema</option>
    </select>
  </p>
  <br />
  <br />
    <input type="submit" name="enviar" id="enviar" value="Cadastrar" class="btn" />
    <input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</div><!--cliente-->

Compartilhar este post


Link para o post
Compartilhar em outros sites


Boa noite,

 

Mano, qual a dificuldade?

$sql = mysql_query("buscar valor no banco");

 

<select name="nivel" id="nivel">

 

<?php while($row = $sql ->fetch_assoc()){

 

echo "<option value='".$row['valor']."'>".$row['valor']."</option>";

?>

 

<option value="Senior-Rubi-4W">Senior-Rubi-4W</option>

<option value="Senior-Windows">Senior-Windows</option>

<option value="WK-Sistemas">WK-Sistemas</option>

<option value="Bloqueado">Bloqueado</option>

<option selected="selected">Escolha o Sistema</option>

</select>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

<?php require_once('../../Connections/Admsofit.php'); include "../functions/permicao/Operador.php";?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {  if (PHP_VERSION < 6) {    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;  }   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);   switch ($theType) {    case "text":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;        case "long":    case "int":      $theValue = ($theValue != "") ? intval($theValue) : "NULL";      break;    case "double":      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";      break;    case "date":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;    case "defined":      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;      break;  }  return $theValue;}} $editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) {  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);} if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {  $updateSQL = sprintf("UPDATE usuarios SET user_login=%s, user_senha=%s, user_nivel=%s WHERE user_id=%s",                       GetSQLValueString($_POST['login'], "text"),                       GetSQLValueString($_POST['senha'], "text"),                       GetSQLValueString($_POST['nivel'], "text"),                       GetSQLValueString($_POST['user_id'], "int"));   mysql_select_db($database_Admsofit, $Admsofit);  $Result1 = mysql_query($updateSQL, $Admsofit) or die(mysql_error());   $updateGoTo = "?p=alterar_list-Cliente";   header(sprintf("Location: %s", $updateGoTo));} $colname_alterar = "-1";if (isset($_GET['user_id'])) {  $colname_alterar = $_GET['user_id'];}mysql_select_db($database_Admsofit, $Admsofit);$query_alterar = sprintf("SELECT * FROM usuarios WHERE user_id = %s", GetSQLValueString($colname_alterar, "int"));$alterar = mysql_query($query_alterar, $Admsofit) or die(mysql_error());$row_alterar = mysql_fetch_assoc($alterar);$totalRows_alterar = mysql_num_rows($alterar);?><div id="cliente"><h2>Alterar Cliente</h2><form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">  <p>    <label for="login">      <input name="user_id" type="hidden" id="user_id" value="<?php echo $row_alterar['user_id']; ?>" />      Login:   </label>    <input name="login" type="text" id="login" value="<?php echo $row_alterar['user_login']; ?>" />  </p>  <p>    <label for="senha">Senha:  </label>    <input name="senha" type="password" id="senha" value="<?php echo $row_alterar['user_senha']; ?>" />  </p>  <p>    <label for="nivel">Sistema:</label>    <select name="nivel" id="nivel" title="user_nivel">      <option value="Senior-Rubi-4W">Senior-Rubi-4W</option>      <option value="Senior-Windows">Senior-Windows</option>      <option value="WK-Sistemas">WK-Sistemas</option>      <option value="Bloqueado">Bloqueado</option>    </select>  </p>  <br />  <br />    <input type="submit" name="enviar" id="enviar" value="Atualizar" class="btn" />    <input type="hidden" name="MM_update" value="form1" /></form><p> </p></div><!--cliente--><?phpmysql_free_result($alterar);?> 

como ficaria nesse código assima ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

se entendi bem, seu select (ou list/menu) não se chama "nivel"?

como está aCima?

 

então:

$select=$_POST['nivel'];
echo $select;

ou

echo $_POST['nivel'];

Compartilhar este post


Link para o post
Compartilhar em outros sites

pronto reescrevi

como seria para recuperar o valor no Select(Liste/Menu)?

 

<?php 
require_once('../../Connections/Admsofit.php'); 
include "../functions/permicao/Operador.php";
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$currentPage = $_SERVER["PHP_SELF"];
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "alterar_cliente")) {
  $updateSQL = sprintf("UPDATE usuarios SET user_login=%s, user_senha=%s, user_nivel=%s WHERE user_id=%s",
                       GetSQLValueString($_POST['user_login'], "text"),
                       GetSQLValueString($_POST['user_senha'], "text"),
                       GetSQLValueString($_POST['user_nivel'], "text"),
                       GetSQLValueString($_POST['user_id'], "int"));
 
  mysql_select_db($database_Admsofit, $Admsofit);
  $Result1 = mysql_query($updateSQL, $Admsofit) or die(mysql_error());
 
  $insertGoTo = "?p=alterar_sucesso";
 
  header(sprintf("Location: %s", $insertGoTo));
}
 
$maxRows_Listar = 6;
$pageNum_Listar = 0;
if (isset($_GET['pageNum_Listar'])) {
  $pageNum_Listar = $_GET['pageNum_Listar'];
}
$startRow_Listar = $pageNum_Listar * $maxRows_Listar;
 
$colname_Listar = "-1";
if (isset($_POST['user_login'])) {
  $colname_Listar = $_POST['user_login'];
}
mysql_select_db($database_Admsofit, $Admsofit);
$query_Listar = sprintf("SELECT * FROM usuarios WHERE user_login LIKE %s", GetSQLValueString("%" . $colname_Listar . "%", "text"));
$query_limit_Listar = sprintf("%s LIMIT %d, %d", $query_Listar, $startRow_Listar, $maxRows_Listar);
$Listar = mysql_query($query_limit_Listar, $Admsofit) or die(mysql_error());
$row_Listar = mysql_fetch_assoc($Listar);
 
if (isset($_GET['totalRows_Listar'])) {
  $totalRows_Listar = $_GET['totalRows_Listar'];
} else {
  $all_Listar = mysql_query($query_Listar);
  $totalRows_Listar = mysql_num_rows($all_Listar);
}
$totalPages_Listar = ceil($totalRows_Listar/$maxRows_Listar)-1;
 
$queryString_Listar = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Listar") == false && 
        stristr($param, "totalRows_Listar") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Listar = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Listar = sprintf("&totalRows_Listar=%d%s", $totalRows_Listar, $queryString_Listar);
?>
<script type="text/javascript">
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>
 
<div id="cliente_alt">
<h2>Alterar Cliente</h2>
  <div id="alt">
  <form id="form1" name="form1" method="post" action="">
    Pesquiser Cliente: 
    <label>
      <input type="text" name="user_login" id="user_login" />
    </label>
    <input type="submit" name="pesquisar" id="pesquisar" class="btn" value="Pesquisar" />
  </form>
  <br />
  <table class="tabela" width="570" border="0" cellpadding="4" cellspacing="4">
    <tr>
    <td width="241" align="center" bgcolor="#FFFFFF"></td>
      <td width="227" align="center" bgcolor="#FFFFFF"><strong>Empresa</strong></td>
      <td width="241" align="center" bgcolor="#FFFFFF"><strong>Senha</strong></td>
      <td width="241" align="center" bgcolor="#FFFFFF"><strong>Sistema</strong></td>
      <td width="62" align="center" bgcolor="#FFFFFF"><strong>Alterar</strong></td>
    </tr>
    <?php do { ?>
      <tr>
       <form id="alterar_cliente" name="alterar_cliente" method="POST" action="<?php echo $editFormAction; ?>">
       <td align="center" bgcolor="#FFFFFF"><input name="user_id" type="hidden" id="hiddenField" value="<?php echo $row_Listar['user_id']; ?>" /></td>
        <td align="center" bgcolor="#FFFFFF"><input name="user_login" type="text" id="user_login" value="<?php echo $row_Listar['user_login']; ?>" /></td>
        <td align="center" bgcolor="#FFFFFF"><input name="user_senha" type="text" id="user_login" value="<?php echo $row_Listar['user_senha']; ?>" /></td>
        <td align="center" bgcolor="#FFFFFF">
            <select name="user_nivel" id="user_nivel" >
              <option value="Senior-Rubi-4W">Senior-Rubi-4W</option>
              <option value="Senior-Windows">Senior-Windows</option>
              <option value="WK-Sistemas">WK-Sistemas</option>
              <option value="Bloqueado">Bloqueado</option>
            </select>
        </td>
        <td align="center" bgcolor="#FFFFFF"><input type="submit" name="alterar" id="alterar" value="" class="edt"/></td>
        <input type="hidden" name="MM_update" value="alterar_cliente" />
        </form>
    </tr>
        <?php } while ($row_Listar = mysql_fetch_assoc($Listar)); ?>
  </table>
  <br />
  <table border="0" align="right">
    <tr>
      <td><?php if ($pageNum_Listar > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Listar=%d%s", $currentPage, 0, $queryString_Listar); ?>"><img src="../img/First.gif" /></a>
        <?php } // Show if not first page ?></td>
      <td><?php if ($pageNum_Listar > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Listar=%d%s", $currentPage, max(0, $pageNum_Listar - 1), $queryString_Listar); ?>"><img src="../img/Previous.gif" /></a>
        <?php } // Show if not first page ?></td>
      <td><?php if ($pageNum_Listar < $totalPages_Listar) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Listar=%d%s", $currentPage, min($totalPages_Listar, $pageNum_Listar + 1), $queryString_Listar); ?>"><img src="../img/Next.gif" /></a>
        <?php } // Show if not last page ?></td>
      <td><?php if ($pageNum_Listar < $totalPages_Listar) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Listar=%d%s", $currentPage, $totalPages_Listar, $queryString_Listar); ?>"><img src="../img/Last.gif" /></a>
        <?php } // Show if not last page ?></td>
    </tr>
  </table>
 
  </div><!--alt-->
</div><!--cliente_alt-->
<?php
mysql_free_result($Listar);
?>
 

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.