ERROR:NO DATABASE SELECTED:

Hello, I made a simple program that takes what the user inputs and enters it into my mysql database. But when i run it through my browser, this Error: No database selected apears. 1. I’m not a professional or whatever, 2. table is the name of my table. And i know that the error is from when i try to INSERT INTO my table. It would be appreciated if you could tell me what’s going on. Here is the code:


Input1:

<?php

$link = mysqli_connect(‘HOST’, ‘USER’, ‘PASSWORD’);
if (!$link) {
echo “Part 1 unsuccesful”;
exit();
}

if (!mysqli_set_charset($link, ‘utf8’))
{
echo “Part 2 unsuccesful”;
exit();
}
$dbconnect = mysqli_select_db($link, ‘db’);
if (!$dbconnect)
{ echo “Part 3 unsuccesful”;
die(‘Error;’ . mysql_error());
exit();
}

$stuff = ‘input1’;

if (!empty($stuff)){

$sql = (“INSERT INTO table(Content) VALUES(’$stuff’)”);
if (!mysql_query($sql)) {

die('Error;' . mysql_error());

}

}

?>

Now I am no expert on this stuff, but shouldn’t the link come after, so instead of:
$dbconnect = mysqli_select_db($link, ‘db’);
it should be:
$dbconnect = mysqli_select_db(‘db’, $link);
Check if it solves your problem.

Sponsor our Newsletter | Privacy Policy | Terms of Service