Confirm Code and Switch to login page

1

Friends I'm new to PHP + sql help me here:

  --
-- Estrutura da tabela 'verified_user'
--

 CREATE TABLE IF NOT EXISTS 'verified_user' (
 'id' int(11) NOT NULL AUTO_INCREMENT,
 'email' text NOT NULL,
  'password' text NOT NULL,
  PRIMARY KEY ('id')
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

-- --------------------------------------------------------

--
 -- Estrutura da tabela 'verify'
--

 CREATE TABLE IF NOT EXISTS 'verify' (
  'id' int(11) NOT NULL AUTO_INCREMENT,
  'email' text NOT NULL,
  'password' text NOT NULL,
 'code' text NOT NULL,
 PRIMARY KEY ('id')
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ;

The above Table I am making the call below to try to get the code registered code corresponding, validate, once validated redirect the user to another page index2.php , how can I do this in a simple way in php ? Help me if you can.

 <form method="post" action="verification.php">
 <input type="text" name="email">
 <input type="password" name="code">
 <input type="submit" name="register" Value="Register">
 </form>
    
asked by anonymous 25.07.2016 / 23:46

1 answer

0

Create a page called "verification.php" and place the code below. It will connect in your bank and will select the data registered in the bank. Change the mysql_select_db line there and change the 'bank_name' to the name of your bank. do not forget to put quotation marks around

<?php
//Forma simples
$server = mysql_connect('localhost',root,'');
if($server){
    $banco = mysql_select_db('nome_do_seu_banco');
}
//CAPTURA OS DADOS INFORMADOS NO FORMULÁRIO
$email = $_POST['email'];
$code = $_POST['code'];

$sql = "SELECT * FROM verify WHERE email = '$email' and code = '$code'" ;
$result = mysql_query($sql);
$total = mysql_num_rows($result);

if($total>0){
    //SE ENTROU AQUI, SINAL DE QUE FOI ENCONTRADO 1 REGISTRO PELO MENOS COM O EMAIL E CODIGO DIGITADOS
    //E SE ENCONTROU, SINAL QUE DIGITOU CERTO
    // AI CRIA A SESSÃO E VAI PRA SUA PAGINA;
    session_start();
    $_SESSION['email'] = $email;
    header("location: index2.php"); 
}else{
    //SE ENTROU AQUI, DADOS INCORRETOS, VOLTA PRA PAGINA INDEX
    header("location: index.php");

}

?>
    
26.07.2016 / 04:41