Запустите файл php, когда кнопка отправки в другой HTML-файл - PullRequest
2 голосов
/ 23 октября 2019

Я бы хотел поработать над процессом регистрации, для которого с помощью Google и Youtube я создал страницу «Вход и подписка», а затем опцию переключения, но не могу запустить файл registration.php, как только пользователь предоставит регистрационную информациюв файле login.html. Коды следующие:

<form id="login" class="input-group">
    <input type="text" class="input-field" placeholder="User Id" required>
    <input type="password" class="input-field" placeholder="Enter Password" required>
    <input type="checkbox" class="check-box"><span>Remember Password</span>
    <button type="submit" class="submit-btn">Sign-In</button>
</form>

<form Id="register" class="input-group">
    <input type="text" class="input-field" placeholder="User Id" required>
    <input type="email" class="input-field" placeholder="Email Id" required>
    <input type="password" class="input-field" placeholder="Enter Password" required>
    <input type="password" class="input-field" placeholder="Confirm Password" required>
    <input type="phone-number" class="input-field" placeholder="Mobile Number" required>
    <input type="checkbox" class="check-box"><span>I agree to the terms & conditions</span>
    <button type="submit" class="submit-btn">Sign-Up</button>
</form>

Как выполнить файл registration.php, когда кнопка «Зарегистрироваться» нажата в файле login.html? То же самое касается опции входа в систему.

Ответы [ 2 ]

0 голосов
/ 23 октября 2019

Убедитесь, что вы добавили method="POST" и action="path/function.php" и name="desiredName" в ваши формы следующим образом:

<form id="login" class="input-group" method="POST" action="file_path/login.php">
    <input type="text" class="input-field" placeholder="User Id" name ="user" required>
    <input type="password" class="input-field" placeholder="Enter Password" name="password" required>
    <input type="checkbox" class="check-box"><span>Remember Password</span>
    <button type="submit" class="submit-btn">Sign-In</button>
</form>

А затем в PHP, чтобы «поймать» данные из поста, выиспользуйте что-то вроде этого:

$this->getpost['user'];

Или

$_POST['user'];
0 голосов
/ 23 октября 2019

Атрибут метода указывает, как отправлять данные формы (данные формы отправляются на страницу, указанную в атрибуте действия).

Данные формы можно отправлять как переменные URL (с методом ="get") или как HTTP post транзакция (с методом = "post").

проверьте здесь для более подробной информации w3schools

<form id="login" class="input-group" method="POST" action="file_path/login.php">
    <input type="text" class="input-field" placeholder="User Id" required>
    <input type="password" class="input-field" placeholder="Enter Password" required>
    <input type="checkbox" class="check-box"><span>Remember Password</span>
    <input type="submit" class="submit-btn" value="Sign-In">
</form>

<form Id="register" class="input-group" method="POST" action="file_path/register.php">
    <input type="text" class="input-field" placeholder="User Id" required>
    <input type="email" class="input-field" placeholder="Email Id" required>
    <input type="password" class="input-field" placeholder="Enter Password" required>
    <input type="password" class="input-field" placeholder="Confirm Password" required>
    <input type="phone-number" class="input-field" placeholder="Mobile Number" required>
    <input type="checkbox" class="check-box"><span>I agree to the terms & conditions</span>
    <input type="submit" class="submit-btn" value="Sign-Up">
</form>

РЕДАКТИРОВАТЬ согласнона ваш комментарий

замените кнопку на тип ввода = "submit" и поставьте @ перед переменной php, чтобы вы не получили неопределенное уведомление об ошибке (@ используется, чтобы избежать уведомления об ошибке)


<div class="header"> 
    <h2>Register here</h2> 
</div> 
<form method="post" action="register.php"> 
    <?php include('errors.php'); ?> 
    <div class="input-group"> 
        <label>Username</label> 
        <input type="text" name="username" value="<?php echo @$username; ?>"> 
    </div> 
    <div class="input-group"> 
            <label>Email</label> 
            <input type="email" name="email" value="<?php echo @$email; ?>"> 
        </div> 
        <div class="input-group"> 
            <label>Password</label> 
            <input type="password" name="password_1"> 
        </div> 
        <div class="input-group"> 
            <label>Confirm Password</label> 
            <input type="password" name="password_2"> 
        </div>


<div class="input-group"> 
    <label>Mobile number</label> 
    <input type="number" name="mobile" value="<?php echo @$mobile; ?>"> 
</div> 
<div class="input-group"> 
    <input type="submit" class="btn" name="reg_user" value="Sign-Up">
</div> 
</form>

создать файл register.php и в register.php

<?php
$con = mysqli_connect("localhost", "username", "password", "dbname") or trigger_error("Unable to connect to the database");
    if(isset($_POST['reg_user'])){
        $name = $_POST['username']; //here "username" is what you defined in the "name" field of input form
    //define other variables
        //write your own sql query , here is an example
        $query = "INSERT INTO table(name) VALUES(?)";
        $stmt = mysqli_stmt_init($con);
        if(!mysqli_stmt_prepare($stmt,$query)){
            echo "Error";
        }else{
            mysqli_stmt_bind_param($stmt,"s",$name);
            mysqli_stmt_execute($stmt);
        }
    }
?>
...