0

i have been trying to create a small php script which inputs data from an html form into a phpmyadmin database and have come across some errors which i cant fix, heres my code;

<html>
  <head>
    <title>Insert form data</title>
    <link rel="stylesheet" type="text/css" href="mystyle.css">
  </head>
 <body>
    <center>
    <h1>Online Stock Management</h1>
    <br>
    <p>Hello and welcome to Online Stock Management for small businesses. Please enter your details below to access your area.</p>
    <form action="insert.php" method="post">
        Business Name : <input type="text" name="businessName">
        <br>
        Name : <input type="text" name="name">
        <br>
        Email : <input type="text" name="email">
        <br>
            <input type="submit" value="Insert">

And

<?php

$username = "root";
$password = "";
$hostname = "localhost"; 

//connection to phpmyadmin
$dbhandle = mysqli_connect($hostname, $username, $password) or die("Unable to connect to MySQL");

//connection to database 1012405 in phpmyadmin
mysql_select_db($dbhandle, '1012405') or die("Unable to connect to 1012405");

//insert html form into database
$insertquery= " INSERT INTO users(
        businessName,
        name,
        email
            ) VALUES (
        '".$_POST['businessName']."',
        '".$_POST['name']."',
        '".$_POST['email']."')";


$value = mysqli_query($dbhandle,$insertquery);
if (!$value){
die("Error could not insert " . mysqlerror());
}

?>

This is my users table enter image description here

And this is the error I'm receiving enter image description here

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
trezremay
  • 35
  • 6

2 Answers2

1
mysql_select_db($dbhandle, '1012405') or die("Unable to connect to 1012405");

I think It should be

mysqli_select_db($dbhandle, '1012405') or die("Unable to connect to 1012405");

you can connect to your db like this as well

$dbhandle = mysqli_connect($hostname, $username, $password, '1012405') or die("Unable to connect to MySQL");
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
vishi
  • 31
  • 4
0

Try it...

$dbhandle = mysqli_connect($hostname, $username, $password, '1012405') or die("Unable to connect to MySQL");
Ruchi
  • 17
  • 6