-1

First off the other questions that have been anwered don't help me. I still have the same problem so please don't mark this as a duplicate. Also I have to add data to my database.

Code:

<html>
<head>
<title>Vanille</title>
</head>
<body>
<?php
include ("realhtmlinphpfile.php"); 
mysqli_connect("localhost")
or die ("Fehler");

mysqli_select_db("test34")
or die ("Verbindung nicht möglich..."); 

$Test1 = $_POST["Test1"]; 
$Test2 = $_POST["Test2"];
$Text3 = $_POST["Test3"]; 
$Test4 = $_POST["Test4"];

if($Test1 == "" or $Test2 == "" or $Test3 == "" or $Test4 == "") {
echo "FAIL";
} else {

$eintrag = "INSERT INTO test34
(datum, autor, newstext)

VALUES 
('$test1', '$test2', '$test3', '$test4')";

}

mysql_close($verbindung); 
?>
</body>                              
</html>
Dharman
  • 30,962
  • 25
  • 85
  • 135
DarkYagami
  • 93
  • 7
  • 1
    Did you even try to lookup the php manual? http://php.net/mysqli_select_db – wmk Oct 30 '15 at 08:44
  • check this out.. http://www.w3schools.com/php/func_mysqli_select_db.asp – 6339 Oct 30 '15 at 08:47
  • What is your problem? If you suspect two params, did you try it?! – Mattias Lindberg Oct 30 '15 at 09:00
  • You could've found your answer here: https://stackoverflow.com/questions/19065282/use-mysqli-connect-and-mysql-select-db. Or in the php manual: http://php.net/mysqli_select_db –  Oct 30 '15 at 09:26

4 Answers4

1

mysqli_select_db() requires 2 parameters :

  1. The connection to the database (usually $link);
  2. The database name

So for your connection your code should look like this :

$link = mysqli_connect("localhost") or die ("Fehler");

mysqli_select_db($link ,"test34") or die ("Verbindung nicht möglich..."); 

You can check the doc of mysqli_select_db() for more infos : http://php.net/manual/fr/mysqli.select-db.php

Jan
  • 42,290
  • 8
  • 54
  • 79
Nirnae
  • 1,315
  • 11
  • 23
1

You can connect Database mysqli as follow

<?php
$con = mysqli_connect("localhost","user","password","my_db")  or die ("Fehler");
return $con;
?>

Or

<?php
$con = mysqli_connect("localhost","user","password");
$sel = mysqli_select_db($con , "my_db")  or die ("Fehler");
return $sel;
?>
php-coder
  • 955
  • 1
  • 12
  • 23
0

You should pass the connection object as the first parameter:

$con=mysqli_connect("localhost","username","password");
//    mysqli_connect("localhost);
mysqli_select_db($conn,"test34");
Jan
  • 42,290
  • 8
  • 54
  • 79
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41
-2

The code looks really messy :-) You will need to save the handle from mysql_connect() to a variable and have this as the first parameter.

$c = mysqli_connect("localhost") or die ("Fehler");
mysqli_select_db($c, "test34");

PS: In my former answer I have mixed the parameters myself as I was referring to the older mysql functions.

Jan
  • 42,290
  • 8
  • 54
  • 79