SQL和PHP的空白条目

时间:2017-06-30 15:01:36

标签: php mysql

我在这个网站和其他网站上尝试了其他解决方案,但无法使其正常运行。 当我按下刷新空数据发送到phpmyadmin,并进行空白输入。 当我按下提交时,它不发送任何内容,甚至不是空白。

我的数据库连接正常。 康恩

<?php

$host = 'localhost';      // min host.
$user = 'root';           // mit brugernavn.
$password = 'mysql';           // mit password. Er tomt for Windows-brugere, men root for Mac-brugere.
$database = 'boliger';    // navnet på min database.

$conn = new mysqli($host, $user, $password, $database);

mysqli_set_charset($conn, 'utf8');

if ($conn->connect_error)
    die($conn->connect_error);
?>

索引

<?php
include_once 'conn.php';
?>


<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <link rel="apple-touch-icon" sizes="76x76" href="assets/img/apple-icon.png" />
        <link rel="icon" type="image/png" href="assets/img/favicon.png" />
        <title>Bolig</title>

        <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
        <meta name="viewport" content="width=device-width" />

        <!-- CSS Files -->
        <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
        <link href="assets/css/paper-bootstrap-wizard.css" rel="stylesheet" />

        <!-- CSS Just for demo purpose, don't include it in your project -->
        <link href="assets/css/demo.css" rel="stylesheet" />

        <!-- Fonts and Icons -->
        <link href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.css" rel="stylesheet">
        <link href='https://fonts.googleapis.com/css?family=Muli:400,300' rel='stylesheet' type='text/css'>
        <link href="assets/css/themify-icons.css" rel="stylesheet">
    </head>

    <body>
        <div class="image-container set-full-height" style="background-image:">
            <!--   Creative Tim Branding   -->



            <!--   Big container   -->
            <div class="container">
                <div class="row">
                    <div class="col-sm-8 col-sm-offset-2">

                        <!--      Wizard container        -->
                        <div class="wizard-container">
                            <div class="card wizard-card" data-color="green" id="wizard">
                                <form  method="POST" action="process.php">
                                    <!--        You can switch " data-color="green" "  with one of the next bright colors: "blue", "azure", "orange", "red"       -->

                                    <div class="wizard-header">
                                        <h3 class="wizard-title">Søg bolig</h3>
                                        <p class="category">Denne information vil hjælpe os med, at denne et billed af dine bolig ønsker.</p>
                                    </div>
                                    <div class="wizard-navigation">
                                        <div class="progress-with-circle">
                                            <div class="progress-bar" role="progressbar" aria-valuenow="1" aria-valuemin="1" aria-valuemax="4" style="width: 15%;"></div>
                                        </div>
                                        <ul>
                                            <li>
                                                <a href="#location" data-toggle="tab">
                                                    <div class="icon-circle">
                                                        <i class="ti-map"></i>
                                                    </div>
                                                    Placering
                                                </a>
                                            </li>
                                            <!--
                <li>
                                                    <a href="#type" data-toggle="tab">
                                                            <div class="icon-circle">
                                                                    <i class="ti-direction-alt"></i>
                                                            </div>
                                                            Type
                                                    </a>
                                            </li>
                                            -->
                                            <li>
                                                <a href="#facilities" data-toggle="tab">
                                                    <div class="icon-circle">
                                                        <i class="ti-panel"></i>
                                                    </div>
                                                    Kontakt Oplysninger
                                                </a>
                                            </li>
                                        </ul>
                                    </div>
                                    <div class="tab-content">
                                        <div class="tab-pane" id="location">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <h5 class="info-text"> Lade os starte med, at få de grundlæggende oplysninger.</h5>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset-1">
                                                    <div class="form-group">
                                                        <label>Kommune 1</label>
                                                        <input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
                                                    </div>
                                                    <div class="form-group">
                                                        <label>Kommune 2</label>
                                                        <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
                                                    </div>
                                                    <div class="form-group">
                                                        <label>Kommune 3</label>
                                                        <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
                                                    </div>
                                                    <div class="form-group">
                                                        <label>Kommune 4</label>
                                                        <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
                                                    </div>
                                                    <div class="form-group">
                                                        <label>Kommune 5</label>
                                                        <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">
                                                    </div>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset">
                                                    <div class="form-group">
                                                        <label>Antal Voksne</label>
                                                        <select class="form-control">
                                                            <option disabled="" selected="">- Voksne -</option>
                                                            <option>1 Person</option>
                                                            <option>2 Personer </option>
                                                            <option>3 Personer</option>
                                                            <option>4 Personer</option>
                                                            <option>5 Personer</option>
                                                            <option>6+ Personer</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset">
                                                    <div class="form-group">
                                                        <label>Antal Børn</label>
                                                        <select class="form-control">
                                                            <option disabled="" selected="">- Børn -</option>
                                                            <option>1 Barn</option>
                                                            <option>2 Børn </option>
                                                            <option>3 Børn</option>
                                                            <option>4 Børn</option>
                                                            <option>5 Børn</option>
                                                            <option>6+ Børn</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset">
                                                    <div class="form-group">
                                                        <label>Antal Rum</label>
                                                        <select class="form-control">
                                                            <option disabled="" selected="">- Værelser -</option>
                                                            <option>1 Værelse</option>
                                                            <option>2 Værelser </option>
                                                            <option>3 Værelser</option>
                                                            <option>4 Værelser</option>
                                                            <option>5 Værelser</option>
                                                            <option>6+ Værelser</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset">
                                                    <div class="form-group">
                                                        <label>Maksimum husleje inkl. forbrug</label>
                                                        <div class="input-group">
                                                            <input type="text" class="form-control" placeholder="Husleje">
                                                            <span class="input-group-addon">DKK</span>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="col-sm-5 col-sm-offset">
                                                    <div class="form-group">
                                                        <label>Kæledyr</label>
                                                        <div class="checkbox">
                                                            <label><input type="checkbox" value="">Hvis du har kæledyr og ønsker, at det er tilladt i den nye bolig, så sæt venligst et flueben.</label>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!--
                                        <div class="tab-pane" id="type">
                                            <h5 class="info-text">Hvilken form for bolig har du?</h5>
                                            <div class="row">
                                                <div class="col-sm-8 col-sm-offset-2">
                                                    <div class="col-sm-4 col-sm-offset-2">
                                                                                                    <div class="choice" data-toggle="wizard-checkbox">
                                                            <input type="checkbox" name="jobb" value="Design">
                                                            <div class="card card-checkboxes card-hover-effect">
                                                                <i class="ti-home"></i>
                                                                                                                    <p>Lejlighed</p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-4">
                                                                                                    <div class="choice" data-toggle="wizard-checkbox">
                                                            <input type="checkbox" name="jobb" value="Design">
                                                            <div class="card card-checkboxes card-hover-effect">
                                                                <i class="ti-package"></i>
                                                                                                                    <p>Der komme flere på, i takt med, at vi udvider.</p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        -->
                                        <div class="tab-pane" id="facilities">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <h5 class="info-text">Dine kontaktoplysninger</h5>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset-1">
                                                    <div class="form-group">
                                                        <label>Navn</label>
                                                        <input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast navn">
                                                    </div>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset">
                                                    <div class="form-group">
                                                        <label>Email</label>
                                                        <input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast email">
                                                    </div>
                                                </div>
                                                <div class="col-sm-5 col-sm-offset-1">
                                                    <div class="form-group">
                                                        <label>Mobil nummer</label>
                                                        <input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast mobil nummer">
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                        <div class="wizard-footer">
                                            <div class="pull-right">
                                                <input type='button' class='btn btn-next btn-fill btn-success btn-wd' name='next' value='Næste' />
                                                <input type='submit' class='btn btn-finish btn-fill btn-success btn-wd' name="submit" value="Submit" />
                                            </div>

                                            <div class="pull-left">
                                                <input type='button' class='btn btn-previous btn-default btn-wd' name='previous' value='Tilbage' />
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                </form>
                            </div>
                        </div> <!-- wizard container -->
                    </div>
                </div> <!-- row -->
            </div> <!--  big container -->

            <div class="footer">
                <div class="container text-center">
                </div>
            </div>
        </div>
<?php
 if( isset( $_POST['submit'] ) )
    {
        $hvemErDu = $_POST['hvemErDu'];
    } else {
       echo error;
    }



    //connecting to sql database
    $conn or die( $conn->error );

    //inserting details into table
    $insert = $conn->query( "INSERT INTO lejere ( `hvemErDu` ) VALUE ( '$hvemErDu' )" );

    //closing mysqli connection
    $mysqli->close;


//if ($_POST) {
//    if (isset($_POST["Submit"])) {
//        // $hvemErDu = $_POST["hvemErDu"];
//        // Se side 250
//        mysqli_query($conn, "INSERT INTO lejere (hvemErDu)
//VALUES ('$_POST[hvemErDu]')";
//        

?>
    </body>

    <!--   Core JS Files   -->
    <script src="assets/js/jquery-2.2.4.min.js" type="text/javascript"></script>
    <script src="assets/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="assets/js/jquery.bootstrap.wizard.js" type="text/javascript"></script>

    <!--  Plugin for the Wizard -->
    <script src="assets/js/paper-bootstrap-wizard.js" type="text/javascript"></script>

    <!--  More information about jquery.validate here: http://jqueryvalidation.org/  -->
    <script src="assets/js/jquery.validate.min.js" type="text/javascript"></script>

</html>

过程

<?php
//process.php
if ($_SERVER["REQUEST_METHOD"] == "POST") {//Check it is coming from a form
    $u_name = $_POST["hvemErDu"]; //set PHP variables like this so we can use them anywhere in code below
    //$u_email = $_POST["user_email"];
    //$u_text = $_POST["user_text"];

    //print output text
    print "Hello " . $u_name . "!, we have received your message and email "; //.$u_email;
    print "We will contact you very soon!";
}
?>

1 个答案:

答案 0 :(得分:0)

您的表单如何?你有“提交”输入吗?

从我在代码中看到的,每次发送表单时都会运行SQL语句,没有任何条件,您最好将查询放在条件括号内,例如:

<?php
if (isset( $_POST['submit'] ))
{
    $hvemErDu = $_POST['hvemErDu'];

    //connecting to sql database
    $conn or die( $conn->error );

    //inserting details into table
    $insert = $conn->query("INSERT INTO lejere ( `hvemErDu` ) VALUE ( '$hvemErDu' )");

    //closing mysqli connection
    $mysqli->close;
} else
{
    echo 'error';
}
?>

注意你也回应错误 - 我不确定你是否想要回显字符串'error'或变量$ error。

但是,这一次看起来你似乎没有任何记录 - 甚至不是空白记录,你能展示整个表格代码吗?

<强>更新

至于你的代码,请注意当你发布表单时,你将它提交给process.php,该文件是否存在?因为您的代码不起作用,除非您将表单提交到同一页面,如下面的代码:

// Send the form to the same page - index.php
<form  method="POST">

<强>更新

你还有另一个问题,你有很多共享同名的输入:hvemErDu。 您必须为每个输入指定一个唯一的名称,否则最新输入的值将被提交给服务器。

这是来自index.php代码:

<label>Kommune 1</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Kommune du gerne vil have bolig i?">

<label>Navn</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast navn">

<label>Email</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast email">

<label>Mobil nummer</label>
<input type="text" name="hvemErDu" class="form-control" id="exampleInputEmail1" placeholder="Indtast mobil nummer">