A
A
Atype2018-01-19 10:53:28
PHP
Atype, 2018-01-19 10:53:28

Why is data not being sent to the database with a shortened php link?

I had such a problem that when sending registration data to the database, nothing is sent because I set the htaccess code to remove the .php at the end of the link.
There he is:

RewriteEngine On

RewriteCond %{THE_REQUEST} " (/[^?/]+)\.php"
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)$ /$1.php [L]

If you do not shorten the link, then everything works fine. But I checked with another php code with sending to the database and shortening the link, and everything worked. Maybe to solve this problem, you need to change the htaccess or php code. I have openserver.
PHP registration form code not working when shortening link:
<meta charset="UTF-8">
<?php 
$dbc = mysqli_connect('localhost','root','','lesson');
if(isset($_POST['submit'])){
  $username  = mysqli_real_escape_string($dbc, trim($_POST['username' ]));
  $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
  $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
  if(!empty($username) && !empty($password1) && !empty($password2) && $password1 == $password2){
    $query = "SELECT * FROM `signup` WHERE username = '$username'";
    $data = mysqli_query($dbc, $query);
    if(mysqli_num_rows($data) == 0){
      $query = "INSERT INTO `signup` (username,password) VALUES ('$username',SHA('$password1'))";
      mysqli_query($dbc,$query);
      echo 'регистрация завершена';
      mysqli_close($dbc);
      exit();		
    }
    else{
      echo 'логин уже существует';
    }

  }	
}
 ?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Document</title>
</head>
<body>
<center>
<form method="POST" action="<?=$_SERVER['PHP_SELF']; ?>">
  <label for="username">логин</label><br>
  <input type="text" name="username"><br>

  <label for="password">пароль</label><br>
  <input type="password" name="password1"><br>

  <label for="password">повторите</label><br>
  <input type="password" name="password2"><br>

  <button name="submit">готово</button><br>
</form>
</center>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Atype, 2018-01-21
@Twedis

I solved this problem instead of the htaccess code, I found the htaccess code with which the link is shortened and sent to the database
htaccess code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question