简体   繁体   English

PHP的登录表格提交按钮不起作用

[英]php login form submit button doesn't work

My php login form doesn't work, i can't find the problem. 我的php登录表单不起作用,我找不到问题。 I tested the sql query in php with fixed values and it works (without the button). 我用固定值测试了php中的sql查询,它可以工作(没有按钮)。 So my guess is that its the submit button. 所以我的猜测是它的“提交”按钮。

The database works fine, i can select items from it but i can't insert data with a submit form. 数据库工作正常,我可以从中选择项目,但不能使用提交表单插入数据。

<?php

session_name('LoginForm');
@session_start();

error_reporting(0);
include("config.php");

?>


<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
        <?php include_once("analyticstracking.php"); ?>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>test</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" sizes="57x57" href="/img/apple-icon-57x57.png">
        <link rel="apple-touch-icon" sizes="60x60" href="/img/apple-icon-60x60.png">
        <link rel="apple-touch-icon" sizes="72x72" href="/img/apple-icon-72x72.png">
        <link rel="apple-touch-icon" sizes="76x76" href="/img/apple-icon-76x76.png">
        <link rel="apple-touch-icon" sizes="114x114" href="/img/apple-icon-114x114.png">
        <link rel="apple-touch-icon" sizes="120x120" href="/img/apple-icon-120x120.png">
        <link rel="apple-touch-icon" sizes="144x144" href="/img/apple-icon-144x144.png">
        <link rel="apple-touch-icon" sizes="152x152" href="/img/apple-icon-152x152.png">
        <link rel="apple-touch-icon" sizes="180x180" href="/img/apple-icon-180x180.png">
        <link rel="icon" type="image/png" sizes="192x192"  href="/img/android-icon-192x192.png">
        <link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="96x96" href="/img/favicon-96x96.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
        <link rel="manifest" href="/img/manifest.json">
        <meta name="msapplication-TileColor" content="#ffffff">
        <meta name="msapplication-TileImage" content="/img/ms-icon-144x144.png">
        <meta name="theme-color" content="#ffffff">


        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

        <link rel="stylesheet" href="css/main.css">
        <link href='http://fonts.googleapis.com/css?family=Roboto:400,300,500' rel='stylesheet' type='text/css'>
        <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
        <script src="js/jquery-1.8.2.min.js"></script>
        <script src="js/jquery.validate.min.js"></script>
        <script src="js/main.js"></script>




    </head>
    <body>

            <div id="login-form" class="login-form" name="form1">
                <ul>
                        <li><a class="active" href="index.php">Home</a></li>
                        <li><a href="register.php">register</a></li>
                </ul>

                <?php
                    $servername = "localhost";
                    $username = "root";
                    $password = "";
                    $dbname = "test";

                    // Create connection
                    $conn = mysqli_connect($servername, $username, $password, $dbname);
                    // Check connection
                    if (!$conn) {
                        die("Connection failed: " . mysqli_connect_error());
                    }
                // If form submitted, insert values into the database.
                     if ( isset($_POST['submit']) ) {
                        $email = $_POST['email'];                   
                        $password = $_POST['password'];                 
                        $name = $_POST['name'];                 
                        $phone = $_POST['phone'];               
                        $student =$_POST['student'];                                    
                        $city = $_POST['city'];                                     
                        $street = $_POST['street'];                                         
                        $address = $_POST['address'];                                       
                        $zipcode = $_POST['zipcode'];


                        $password = mysqli_real_escape_string($conn, $password);                    
                        $name = mysqli_real_escape_string($conn, $name);                
                        $phone = mysqli_real_escape_string($conn, $phone);              
                        $student = mysqli_real_escape_string($conn, $student);                                  
                        $city = mysqli_real_escape_string($conn, $city);                                    
                        $street = mysqli_real_escape_string($conn, $street);                                        
                        $address = mysqli_real_escape_string($conn, $address);                                  
                        $zipcode = mysqli_real_escape_string($conn, $zipcode);


                        $query = "INSERT into php_users_login (email, password, name, phone, student, city, street, address, zipcode)) VALUES ('$email', '$password)', '$name', '$telefoon', '$student', '$city','$street','$address','$zipcode')";
                        $result = mysqli_query($conn,$query);
                        if ($res) {
                            $errTyp = "success";
                            $errMSG = "Successfully registered, you may login now";
                            unset($name);
                            unset($email);
                            unset($pass);
                           } else {
                            $errTyp = "danger";
                            $errMSG = "Something went wrong, try again later..."; 
                           }
                     }
                ?>
                <div class="form-content" >
                <h1>Registreren</h1>
                <form name="registration" action="" method="post">
                <table>
                <tr>
                    <td>E-mail</td>
                    <td><input type="email" name="email" placeholder="E-mail" required /></td>
                </tr>
                <tr>
                    <td>password:</td>
                    <td><input type="password" name="password" placeholder="password" required /></td>
                </tr>
                <tr>
                    <td>name:</td>
                    <td><input type="name" name="name" placeholder="name" required /></td>
                </tr>
                <tr>
                    <td>phone:</td>
                    <td><input type="phone" name="phone" placeholder="phone" required /></td>
                </tr>
                <tr>
                    <td>Student:</td>
                    <td><input type="student" name="student" placeholder="student" required /></td>
                </tr>
                <tr>
                    <td>city:</td>
                    <td><input type="city" name="city" placeholder="city" required /></td>
                </tr>
                <tr>
                    <td>street:</td>
                    <td><input type="street" name="street" placeholder="street" required /></td>
                </tr>
                <tr>
                    <td>address:</td>
                    <td><input type="address" name="address" placeholder="address" required /></td>
                </tr>
                <tr>
                    <td>zipcode:</td>
                    <td><input type="zipcode" name="zipcode" placeholder="zipcode" required /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><button type="submit" class="submit" name="submit">Register</button></td>
                </tr>
                </table>
                </form>
                </div>



            </div>   
    </body>
</html>

Your code is - 您的代码是-

$query = "INSERT into php_users_login (email, password, name, phone, student, city, street, address, zipcode)) VALUES ('$email', '$password)', '$name', '$telefoon', '$student', '$city','$street','$address','$zipcode')";

Here an extra ) in column field city, street, address, zipcode)) and another is your values VALUES ('$email', $password) Probably that was the problem on inserting. 这是在列字段city, street, address, zipcode))一个额外的) city, street, address, zipcode)) ,另一个是您的值VALUES ('$email', $password)可能是插入时出现的问题。 Please remove the extra braces or try the following code - 请删除多余的花括号或尝试以下代码-

$query = "INSERT into php_users_login (email, password, name, phone, student, city, street, address, zipcode) VALUES ('$email', '$password', '$name', '$telefoon', '$student', '$city','$street','$address','$zipcode')"

Like @Md said. 就像@Md说的那样。 It was a database error.. The database error is not display in php code. 这是数据库错误。数据库错误未显示在php代码中。 You can use try {}catch(){} 您可以使用try {} catch(){}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM