Database and HTML/PHP?

It works, however is it correct?

PHP:
// Database details
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'resellers';

// Connects to your Database 
$db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
if (isset($_POST["submit"])) {
        $Name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $Email = $_POST['email'];
        $Mobile = $_POST['cell_number'];
        $delivery_address = $_POST['delivery_address'];
        
if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$statement = $db->prepare("INSERT INTO myresellers (`Name`, `LastName`, `Email`, `Cellphone`, `Address`) VALUES (?, ?, ?, ?, ?)");
/* Bind parameters. Types: s = string, i = integer, d = double,  b = blob */
$statement->bind_param('sssis', $Name, $last_name, $Email, $Mobile, $delivery_address);
$statement->execute();
$statement->close();
    }
?>
 
Is the information in this link valid and relevant? ( I am so scared to learn out dated stuff)

https://www.binpress.com/tutorial/using-php-with-mysql-the-right-way/17

Secondly what is the difference between:
Code:
$connection = mysqli_connect('localhost',$username,$password,$dbname);
and
Code:
$connection = new mysqli('localhost',$username,$password,$dbname);

I'm not 100% sure but I think the "new" is used when there is more than one part of your site using that db connection.

It creates an instance.
 
Top
Sign up to the MyBroadband newsletter
X