3
I have the following situation: I have a page (ex: EDIT.PHP) that will be where the information that was previously registered by a form (User registration form) will be edited. The point is, at the end of this EDIT.PHP page, you will have a save button (where you will be redirected to a function that will make the INSERT in the base). I wonder if with PHP I could, when opening this page had some validation to do with a query to the bank because when this particular user was sex = M, for example, did not enable the SAVE button, letting preview but not save.
IS BRINGING BOTH SEXES WITH BUTTON DISABLED
<?php
@ini_set('display_errors', '1');
error_reporting(E_ALL);
$id = $_GET["id"];
settype($id, "integer");
mysql_connect("localhost", "root", "");
mysql_select_db("banco");
$resultado = mysql_query("select * from tabela where id_tabela = $id");
$dados = mysql_fetch_array($resultado);
if($dados["sexo"] == "M") {
$checkedM = "checked=\"checked\"";
$checkedF = "";
} else {
$checkedM = "";
$checkedF = "checked=\"checked\"";
}
$sqlstatus = mysql_query("select * from tabela where sexo = 'M' GROUP BY sexo");
$res = mysql_num_rows($sqlstatus);
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cadastro</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="salvar_edicao.php">
<input type="hidden" name="id" id="id" value="<?php echo $id;?>" />
<h2 align="center"><strong>Edição de Cadastro PHP/MYSQL </strong></h2>
<table width="390" border="1" align="center">
<tr>
<td width="165">Nome</td>
<td width="209"><input name="nome" type="text" id="nome" value="<?php echo $dados["nome"];?>" /></td>
</tr>
<tr>
<td>Sobrenome</td>
<td><input name="sobrenome" type="text" id="sobrenome" value="<?php echo $dados["sobrenome"];?>" /></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email" type="text" id="email" value="<?php echo $dados["email"];?>" /></td>
</tr>
<tr>
<td>Sexo</td>
<td><input name="sexo" type="radio" value="M" <?php echo $checkedM;?> />
Masculino
<input name="sexo" type="radio" value="F" <?php echo $checkedF;?> />
Feminino </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Gravar" <?php echo $res > 0 ? 'disabled' : '' ; ?> /></td> //Com o 'disabled' na frente trás tudo desabilitado, e com ele na frente traz habilitado.
</tr>
</table>
</form>
</body>
</html>
You came to give
print_r($dados); die();
to see what returns?– Ivan Ferrer