A
A
Alexander Bagirov2015-01-20 19:04:07
PHP
Alexander Bagirov, 2015-01-20 19:04:07

Why is the wrong data being inserted into the database (again)?

Good evening. I have a registration page index.php :

<!DOCTYPE html>
<html lang="ru">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../favicon.ico">

    <title>Регистрация</title>

    <!-- Custom styles for this template -->
    <link href="signin.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="container">

      <form class="form-signin" role="form" action="register.php" method="POST">
        <h2 class="form-signin-heading">Пожалуйста, зарегистрируйтесь</h2>
        <input type="email" name="email" class="form-control" placeholder="Email" required autofocus>
        <br />
        <input type="text" name="name" class="form-control" placeholder="Имя (Например, Миша, Маша)" required>
        <br />
        <input type="password" name="password" class="form-control" placeholder="Пароль" required>
        
        <input type="password" name="password2" class="form-control" placeholder="Повторите пароль" required>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Отправить</button>
      </form>

    </div> <!-- /container -->
    
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
    
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    
  </body>
</html>

Everything is passed to register.php :
<?php
    $name = trim(mysql_real_escape_string($_REQUEST['name']));
    $email = trim(mysql_real_escape_string($_REQUEST['email']));
    $password = trim(mysql_real_escape_string($_REQUEST['password']));
    $password2 = trim(mysql_real_escape_string($_REQUEST['password2']));
    
    include('../db.php');
    
    $res_name = mysql_query ("SELECT * FROM `users` WHERE `login`='$name';");
    $res_email = mysql_query ("SELECT * FROM `users` WHERE `email`='$email';");
    
    if (mysql_num_rows($res_name) == 0) {
        if (mysql_num_rows($res_email) == 0) {
            if ($password == $password2) {
                include('insert.php');
            }
            else {
                die ("Пароли не совпадают");
            };
        }
        else {
          die ("Email занят");  
        };
    }
    else {
        die ("Имя занято");
    };
    
    header("Location: http://site.ru/");
    exit;
?>

insert.php :
<?php

    $secure = md5($password . $name);
    
    $sql = "INSERT INTO users (`name`, `email`, `password`)
                VALUES('{$name}', '{$email}', '{$secure}');";
                
    mysql_query($sql)
        or die(mysql_error());
?>

In this case, only the password is inserted into the database. the rest of the fields are empty. Why?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IceJOKER, 2015-01-20
@alexbagirov

before $sql = ...
write var_dump($name, $email); - check whether they are empty or not.
if empty - correct, if not, then check the type of fields in the database.
and learn hardcore debugging - die(var_dump($var)); // check each step and see where data is lost or not received, turn on error display

A
Andrey Nikiforov, 2017-07-24
@squitcher

I tried about 10 plugins
https://wordpress.org/plugins/rich-reviews/#description
the only normal, free plugin, with all the amenities, I don’t understand why plugins for $ 100 are promoted everywhere in Russian blogs and understand how they work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question