1
Good morning, you guys. I’m facing a somewhat embarrassing problem. I can update the user via the panel I built, but I can’t add a new user to it.
Follows the code.
<?
if (isset($_POST['submitted'])) {
$matricula = $_POST['matricula'];
$nome = $_POST['nome'];
$senha = md5($_POST['senha']);
$email = $_POST['email'];
$nivel = $_POST['nivel'];
$funcao = $_POST['funcao'];
$menus = implode(",", $_POST['menus']);
$acesso = $_POST['acesso'];
$sql = "
INSERT INTO tbl_usuarios(
nome_usuario,
login_usuario,
senha_usuario,
email_usuario,
nivel_usuario,
funcao_usuario,
menus_usuario,
acesso_usuario,
)
VALUES(
'".$nome."',
'".$matricula."',
'".$senha."',
'".$email."',
'".$nivel."',
'".$funcao."',
'".$menus."',
'".$acesso."',
)";
$sucesso = mysql_query($sql) or die(mysql_error());
$id = mysql_insert_id();
if ($sucesso){
echo "<p class='sucesso'>Dados inseridos corretamente - CÓDIGO USUÁRIO: ".$id."</p>";
}else
die(mysql_error());
}
?>
<br />
<form id="frmUsuarios" name="frmUsuarios" action='#' method='POST'>
<table border="0" id="tabela_incluir">
<tr class="cor2">
<td class="dir">Matrícula*:</td>
<td><input type="text" size="6" id="matricula" name="matricula" class="input validate[required,custom[onlyNumberSp]]" onblur="validaUser()" maxlength="6" /> <span id="valid"></span>
</td>
</tr>
<tr class="cor2">
<td class="dir">Nome*:</td>
<td><input type="text" size="66" name="nome" class="input validate[required]" /></td>
</tr>
<tr class="cor2">
<td class="dir">Senha*:</td>
<td><input type="password" size="40" name="senha" class="input-normal validate[required]" /></td>
</tr>
<tr class="cor2">
<td class="dir">E-mail*:</td>
<td><input type="email" size="40" name="email" class="input-normal validate[required,custom[email]]" /></td>
</tr>
<tr class="cor2">
<td class="dir">Nível*:</td>
<td><select name="nivel" class="select validate[required]">
<?
$result = mysql_query("SELECT *
FROM tbl_nivel_acesso
ORDER BY 3"
);
print ("<option value='' selected='selected'></option>");
while ($rows = mysql_fetch_array($result)){
print("<option value='{$rows['niv_nivel']}'");
print(">$rows[niv_descricao_nivel]");
print("</option>");
}
?>
</select></td>
</tr>
<tr class="cor2">
<td class="dir">Função*:</td>
<td><select name="funcao" class="select validate[required]">
<?
$result = mysql_query("SELECT *
FROM tbl_funcao
ORDER BY 2"
);
print ("<option value='' selected='selected'></option>");
while ($rows = mysql_fetch_array($result)){
print("<option value='{$rows['id_funcao']}'");
print(">$rows[descricao_funcao]");
print("</option>");
}
?>
</select></td>
</tr>
<tr class="cor2">
<td class="dir">Menus*:</td>
<td>
<input type="checkbox" name="menus[]" value="1" class="validate[required]" /> Cadastros
<br />
<input type="checkbox" name="menus[]" value="2" class="validate[required]" /> Clientes
<br />
<input type="checkbox" name="menus[]" value="3" class="validate[required]" /> Projetos
<br />
<input type="checkbox" name="menus[]" value="4" class="validate[required]" /> Logs
<br />
<input type="checkbox" name="menus[]" value="5" class="validate[required]" /> Boletos
<br />
<input type="checkbox" name="menus[]" value="6" class="validate[required]" /> Pagamentos
<br />
<input type="checkbox" name="menus[]" value="7" class="validate[required]" /> Contas
<br />
<input type="checkbox" name="menus[]" value="8" class="validate[required]" /> Contato
</td>
</tr>
<tr class="cor2">
<td class="dir">Acesso*:</td>
<td>
<select name="acesso" class="select validate[required]">
<option value="" selected="selected"></option>
<option value="1">SIM</option>
<option value="0">NÃO</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="button" class="button" value="Gravar" />
<input type="button" class="button" value="Voltar" name="voltar" onclick="location.href='?acessando=usuarios-listar&titulo=USUÁRIOS';">
<input type='hidden' value='1' name='submitted' />
</td>
</tr>
</table>
</form>
The code works perfectly if I want to edit the user level, the function, but if I create the registration of one, and I click on "record", it does nothing, it does not insert the user into the database with the information, and even shows an error message. Could someone check for me if it contains any errors?
No error gets harder. But looking at your code, if the same script works for
update
, but not toinsert
, is that your BD user is without privilege to enter data?– Thyago ThySofT