T
T
Tiyzz2018-02-12 10:57:59
PHP
Tiyzz, 2018-02-12 10:57:59

How to check records in database?

There is a code that, in my case, writes to the session and all this is sent to the database. But when I enter the same records, he says nothing. How do I make sure that when a record matches, the user is told that such a record exists?

<?php
require_once('db.php');
if(isset($_POST['button'])){
  $login = $_POST['login'];
  $password = $_POST['password'];
  $rpassword = $_POST['r-password'];
  $email = $_POST['email'];
}
if($password){
  echo 'Регистрация прошла успешна';
  mysql_query("INSERT INTO users(login, password, email) VALUES('$login', '$password', '$email')");
}
?>
<!DOCTYPE html>
<html>
<head>
  <title>Регистрация</title>
  <meta charset="utf-8">
</head>
<body>
<form action='az.php' method="post">
  <br>
  <input type="text" name="login" required placeholder="Дата">
  <br>
  <input type="text" name="password" required placeholder="ФИО">
  <br>
  <input type="text" name="email" required placeholder="E-mail"><br>
  <input type="submit" name="button" value='Регистрация на сеанс'>
</form>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2018-02-12
@Eridani

Before writing to the database, pull out the contents of this table and compare (by what field you have there - I don't know) whether there is a record with such a value in the database. If not - add, if there is - then look at the situation according to the situation, what you need

R
rubtsoff, 2018-02-12
@rubsoff

$sql=mysql_query("SELECT FROM users (username, password, email) WHERE username=$fusername");
 if(mysql_num_rows($sql)>=1)
   {
    echo"name already exists";
   }
 else
    {
   //insert query goes here
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question