Olá, queria um código para fazer cadastro, eu tento e tento mas não insere na db 
Print da DB: Print DB
Código que estou tentando:
<?php include("conexao.php"); ?>
<?php
$nome = $_POST['nome'];
$senha = $_POST['senha'];
$verificando = mysql_query("SELECT * FROM usuarios WHERE nome = '$nome' ");
if(mysql_num_rows($verificando) == 1) {
echo "<script>alert('Este nick jรก esta em uso')";
}else{
$sql = mysql_query("INSERT INTO usuarios(nome, senha) VALUES ('$nome', '$senha')");
echo "<script>location.href='central.php';";
}
?>
Verifique se existem dados em $nome e $senha.
Talvez eles não estão chegando.
Caso estejam preenchidos, tente concatenar as variáveis:
“SELECT * FROM usuarios WHERE nome = '” . $nome . “’ “
“INSERT INTO usuarios(nome, senha) VALUES (’” . $nome .”’, '” . $senha ."’)"
Tem como me passar o código completo ? Está dando este erro:
Warning: mysql_query(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Sao_Paulo’ for ‘-3.0/no DST’ instead in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 7 Warning: mysql_query(): Access denied for user ‘’@‘localhost’ (using password: NO) in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 7 Warning: mysql_query(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Sao_Paulo’ for ‘-3.0/no DST’ instead in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 7 Warning: mysql_query(): A link to the server could not be established in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 7 Warning: mysql_num_rows(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Sao_Paulo’ for ‘-3.0/no DST’ instead in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 8 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 8 Warning: mysql_query(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Sao_Paulo’ for ‘-3.0/no DST’ instead in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 11 Warning: mysql_query(): Access denied for user ‘’@‘localhost’ (using password: NO) in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 11 Warning: mysql_query(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Sao_Paulo’ for ‘-3.0/no DST’ instead in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 11 Warning: mysql_query(): A link to the server could not be established in C:\WebServer\Apache2.2\htdocs\c\cadastrando.php on line 11
Cara, tem como passar o arquivo conexao.php?
Talvez tenha algum parâmetro errado ao tentar fazer a conexão.
Boa tarde,
Cara acho que é algo na conexão.
$sql="select * from tabela;
$executeQuery=mysqli_query( $conexaoDoIncludeComOBanco, $sql);
$numberRows=$executeQuery->num_rows;
if($numberRows>0)
{
echo "já existe ";
}
else
{
echo "faz outra coisa" ;
}
se puder colocar o arquivo conexao ajuda. vlw.
Bom, interpretando sua mensagem de erro, alguns pontos:
-
Você precisa definir o timezone usando a função date_default_timezone_set para America/Sao_Paulo…
-
Seu usuário @localhost não têm permissão de acessar a base, artigo a respeito aqui
Tente corrigir esses pontos inicialmente, após vai postando outras mensagens que ocorrer…
Outra coisa, se estiver usando versões mais novas do php, evite usar api mysql_*, dê preferência por PDO ou Mysqli assim você já fica compatível com a versão 7 (que removeu a api antiga) evitando incompatibilidade e o principal, acrescentando mais performance e segurança no seu código…
1 curtida