Bom, não tenho muito conhecimento da interação entre o PHP+MySQL, mas consigo me virar. Eu criei uma área restrita no meu site, e resolvi colocar um local para o usuário poder modificar algumas informações do cadastro dele (nome, data de nascimento, e-mail, telefone, link do facebook e senha). No entanto, o script não está atualizando o banco de dados... Eu tenho um código muito similar a esse rodando na área dos administradores, onde é possível alterar o banco de dados de notícias. O script é quase igual (muda apenas as strings e a tabela onde será realizado o update...), e lá funciona normal... =S O código é o seguinte (ele não é muito "chique", pretendo melhorar ele futuramente): Aqui o usuário têm as informações cadastradas, e altera as que gostaria <?php
session_start();
if (empty($_SESSION['usuario_id'])){
echo "Acesso negado! <script>document.location = '../index.html'</script>";
exit;
}else{
include('config/conexao.php');
$usuario_id = $_SESSION['usuario_id'];
$usuario_nome = $_SESSION['usuario_nome'];
}
// Pegar as informações do usuário
$sql = "SELECT * FROM usuarios WHERE nome = '$usuario_nome' LIMIT 1";
$rsd = mysql_query($sql);
// Pegando os conteúdos
$row = mysql_fetch_array($rsd);
$nome = $row["nome"];
$email = $row["e-mail"];
$telefone = $row["telefone"];
$facebook = $row["facebook"];
$nascimento = $row["nascimento"];
// Inverter a data presente na DB, de Y-m-d para d-m-Y
$nascimento = implode(preg_match("~\/~", $nascimento) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $nascimento) == 0 ? "-" : "/", $nascimento)));
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Opções</title>
</head>
<body>
<form action="modificarinfo.php" method="post" name="modifica" id="modifica">
<table width="100%" border="1">
<tr>
<th scope="row" align="center" width="30%">Nome:</th>
<td align="center"><input name="nome" type="text" id="nome" size="99" value='<?= $nome; ?>' /></td>
</tr>
<tr>
<th scope="row" align="center">Nascimento:</th>
<td align="center"><input name="nascimento" type="text" id="nascimento" size="99" value='<?= $nascimento; ?>' /></td>
</tr>
<tr>
<th scope="row" align="center">E-mail:</th>
<td align="center"><input name="email" type="text" id="email" size="99" value='<?= $email; ?>' /></td>
</tr>
<tr>
<th align="center" scope="row">Telefone:</th>
<td align="center"><input name="telefone" type="text" id="telefone" size="99" value='<?= $telefone; ?>' /></td>
</tr>
<tr>
<th align="center" scope="row">Facebook:</th>
<td align="center"><input name="facebook" type="text" id="facebook" size="99" value='<?= $facebook; ?>' /></td>
</tr>
<tr>
<th align="center" scope="row">Senha:</th>
<td align="center">Senha Antiga: <input name="senhaantiga" type="password" id="senhaantiga" size="50" /><br>
Senha nova: <input name="senhanova1" type="password" id="senhanova1" size="50" /><br>
Senha nova: <input name="senhanova2" type="password" id="senhanova2" size="50" /></td>
</tr>
<tr>
<td colspan="2" valign="middle" align="center"><input type="submit" name="Submit" value="Modificar Cadastro"/></td>
</tr>
</table>
</body>
</html>
Aqui é o script, propriamente falando. Ele que irá dar o update. "modificarinfo.php"
<?php
session_start();
if (empty($_SESSION['usuario_id'])) {
echo "Acesso negado! <script>document.location = '../index.html'</script>";
exit;
}else{
include('config/conexao.php');
$usuario_id = $_SESSION['usuario_id'];
$usuario_nome = $_SESSION['usuario_nome'];
}
// PEGA OS DADOS DO USUÁRIO
$query = "SELECT * FROM usuarios WHERE id = '$usuario_id'";
$resultado = mysql_query($query);
$campo = mysql_fetch_array ($resultado);
$usuario_nome = $campo ['nome'];
$senhaantiga1 = $campo ['senha'];
$usuario_login = $campo ['login'];
// Define o que é o que...
$nome = $_POST["nome"];
$nome = htmlentities($nome, ENT_QUOTES, "ISO-8859-1");
$email = $_POST["email"];
$telefone = $_POST["telefone"];
$facebook = $_POST["facebook"];
$nascimento = $_POST["nascimento"];
$nascimento = implode(preg_match("~\/~", $nascimento) == 0 ? "/" : "-", array_reverse(explode(preg_match("~\/~", $nascimento) == 0 ? "-" : "/", $nascimento)));
$senhaantiga2 = $_POST["senhaantiga"];
$senhaantiga2 = md5($senhaantiga2);
$senhanova1 = $_POST["senhanova1"];
$senhanova1 = md5($senhanova1);
$senhanova2 = $_POST["senhanova2"];
$senhanova2 = md5($senhanova2);
if (($senhaantiga1 == $senhaantiga2) and ($senhanova1 == $senhanova2))
{
$senhanova = $senhanova1;
$sqlinsert = mysql_query("UPDATE usuarios SET nome='$nome', nascimento='$nascimento', e-mail='$email', telefone='$telefone', facebook='$facebook', senha='$senhanova1' WHERE id='$usuario_id' and nome='$usuario_nome' and login='$usuario_login'");
echo "<table width='100%' border='1'>
<tr>
<th scope='row' align='center' width='30%'>Nome:</th>
<td align='center'>$nome</td>
</tr>
<tr>
<th scope='row' align='center'>Nascimento:</th>
<td align='center'>$nascimento</td>
</tr>
<tr>
<th scope='row' align='center'>E-mail:</th>
<td align='center'>$email</td>
</tr>
<tr>
<th align='center' scope='row'>Telefone:</th>
<td align='center'>$telefone</td>
</tr>
<tr>
<th align='center' scope='row'>Facebook:</th>
<td align='center'>$facebook</td>
</tr>
</table>";
}
else {echo 'ERRO!';};
?> Se alguém puder me dar uma luz aí, ficarei muuuito grato!