Hi Guys when I click on the submit button on my register page I'm getting the following errors
Notice: Undefined variable: a in C:\xampp\htdocs\submit-form.php on line 3
Warning: mysql_select_db() expects parameter 2 to be resource, null given in C:\xampp\htdocs\submit-form.php on line 3
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\config.php on line 8
DB select failed: Unknown database 'database_name'
This is the code
config.php
<?php
ini_set('display_errors', true); // change to false when you go live
error_reporting(E_ALL);
//Mysql Connect | mysql_connect("host= 3306","username","");
//Below example to connect in localhost
$a=mysql_connect("localhost","root","");
if($a == false) {
die("Connect failed: ".mysql_error());
}
//select your database
$b=mysql_select_db("database_name",$a);
if($b == false) {
die("DB select failed: ".mysql_error());
}
?>
This is the submit_form.php code
<?php
//select your database
$b=mysql_select_db("database_name",$a);
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$username=$_POST['username'];
//$confirmusername=$_POST['confirmusername'];
$password=$_POST['password'];
$confirmpassword=$_POST['confirmpassword'];
$email=$_POST['email'];
$confirmemail=$_POST['confirmemail'];
//Database connection
require_once("config.php");
//mysql query to insert value to database
$query=mysql_query("INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username', '$password', '$confirmpassword', '$email' , '$confirmemail')");
//if value inserted successyully disply success message
if($query)
{
echo 'Registred successfully..!!</div>';
}else
{
//error message
echo '<unable to registred !!</div>';
}
?>
Hope someone can help me, someone has suggested that i change sql to sqli