Answer the question
In order to leave comments, you need to log in
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]
<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
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 questionAsk a Question
731 491 924 answers to any question