0

i get an "no database selected" error and i can't figure out why. Would be nice if someone could help me out. Code below. There are no typos in there and im using XAMPP/Apache as server so localhost should be right i guess?

 <!--Insert in database-->
    <?php
    $servername = "localhost";
    $dbname = "databank";

    $conn = mysqli_connect($servername, $dbname);

    if(!$conn)
    {
    die("Connection failed: " . mysqli_connect_error());    
    }

    $Kundennummer = $_POST["id"];
    $Vorname = $_POST["vorname"];
    $Nachname = $_POST["nachname"];
    $plz = $_POST["plz"];
    $strasse = $_POST["strasse"];
    $hausnummer = $_POST["hausnummer"];

    $sql = "INSERT INTO kundendaten (Kundennummer, ProduktID, Vorname,Nachname, Hausnummer, Strasse, PLZ)
    Values ('$Kundennummer', '0', '$Vorname', '$Nachname', '$hausnummer', '$strasse', '$plz')";

    if(mysqli_query($conn, $sql))
    {
        echo "DONE";
    }
    else
    {
        echo "ERROR: " . $sql . "<br>" . mysqli_error($conn);
    }
    mysqli_close($conn);
    ?>
0

2 Answers 2

2

Learn mysqli_connect() in php

The valid syntex is

mysqli_connect(host,username,password,dbname,port,socket);
Sign up to request clarification or add additional context in comments.

Comments

0

You have forgot to add username and password into the mysqli_connect.

Please check below sample.

<?php
$con = mysqli_connect("localhost","mysqli-user","mysqli-password","databank");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

I hope this might be helpful for you to resolve your issue.

1 Comment

Thanks, thought username and password wouldn't be necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.