-1

I tried the other solutions on this and other sites, but can´t make it work. When I press refresh empty data is sent to phpmyadmin, and a blank entry is made. When I press submit it doesn´t send anything, not even blank.

My database connection is working. conn

<?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);
?>

index

<?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>

process

<?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!";
}
?>
Taymor
  • 1
  • 2
  • 1
    Please edit your post to NOT DISPLAY YOUR PASSWORD AND INFORMATION – clearshot66 Jun 30 '17 at 15:03
  • Your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use prepared statements with bound parameters, via either the [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php) drivers. [**This post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) has some good examples. – Alex Howansky Jun 30 '17 at 15:04
  • it´s local, I don´t use it anywhere online. – Taymor Jun 30 '17 at 15:05
  • Write insert query in if condition – Ravinder Reddy Jun 30 '17 at 15:08
  • Before anyone says that `VALUE` is incorrect, it's valid in MySQL https://dev.mysql.com/doc/refman/5.7/en/insert.html – Funk Forty Niner Jun 30 '17 at 15:11
  • *"When I press submit it doesn´t send anything, not even blank."* - I don't see a submit button, nor form tags. – Funk Forty Niner Jun 30 '17 at 15:12
  • `echo error;` that's an issue. `error` is treated as a constant. – Funk Forty Niner Jun 30 '17 at 15:14

1 Answers1

0

How does your form look like? Do you have a "submit" input at all?

From what I see in your code, SQL statement runs every time you send the form, without any condition, you better place the query inside the condition brackets, like:

<?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';
}
?>

Pay attention that you also echo error - I'm not sure if you meant to echo the string 'error' or the variable $error.

But again, this time it looks like you won't have any record - not even a blank one, can you show the whole form code?

Update:

As for your code, pay attention that when you post your form, you submit it to process.php, is that file exists at all? as your code wouldn't work unless you submit the form to the same page, as the following code:

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

Update:

You've another problem, you've many inputs which share the same name: hvemErDu. You've to give each input a unique name, otherwise the latest input's value is gonna be submitted to server.

This is from your index.php code:

<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">
MyLibary
  • 1,763
  • 10
  • 17
  • I just updated my OP with full index.php file. Thank you for helping. I have only been working with PHP and SQL a few months. – Taymor Jun 30 '17 at 15:18
  • No worries friend, everything is fine, we're here to assist. As for your code, pay attention that when you post your form, you submit it to process.php, is that file exists at all? as your code wouldn't work unless you submit the form to the same page, as the following code: `// Send the form to the same page - index.php
    `
    – MyLibary Jun 30 '17 at 15:21
  • Update OP again with process. – Taymor Jun 30 '17 at 15:25
  • When you submit the form, do you see the output of the following code? `//print output text print "Hello " . $u_name . "!, we have received your message and email "; //.$u_email; print "We will contact you very soon!";` – MyLibary Jun 30 '17 at 15:27
  • Yes, I do.This is the text. Hello !, we have received your message and email We will contact you very soon! – Taymor Jun 30 '17 at 15:32
  • You've another problem, you've many input which have the same name: hvemErDu (I've counted 4 in the same form). You've to give each input a unique name, otherwise the latest input's value is gonna be submitted to server. – MyLibary Jun 30 '17 at 15:35