Rūdolfs Naumenko Rūdolfs Naumenko - 4 months ago 20
PHP Question

Warning: mysql_select_db() expects parameter 1 to be string,

I am getting this error:


Warning: mysql_select_db() expects parameter 1 to be string, object
given in C:\xampp\htdocs\apply\insert.php on line 11
Database not selectedNot inserted


<?php

$con = mysqli_connect('localhost','root','');

if (!$con)
{
echo 'Not connected to server';
}

if (!mysql_select_db($con,'staff'))
{
echo "Database not selected";
}

$Name = $_POST['username'];
$Email = $_POST['email'];

$sql = "INSERT INTO person (Name, Email) VALUES ('$Name','$Email')";

if(!mysqli_query($con,$sql))
{
echo 'Not inserted';
}
else {
echo 'Inserted';
}

header("refresh:2; url=index.html");

?>

Answer

You are mixing mysql_ with mysqli_ functions.

Change if (!mysql_select_db($con,'staff')) to if (!mysqli_select_db($con,'staff'))

Comments