我一直在尝试创建一个小的PHP脚本,它将数据从html表单输入到phpmyadmin数据库,并遇到了一些我无法修复的错误,这是我的代码;
<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">
并且
<?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());
}
&GT;
这是我的用户表
这是我收到的错误
答案 0 :(得分:1)
mysql_select_db($dbhandle, '1012405') or die("Unable to connect to 1012405");
我认为应该是
mysqli_select_db($dbhandle, '1012405') or die("Unable to connect to 1012405");
您也可以像这样连接到您的数据库
$dbhandle = mysqli_connect($hostname, $username, $password, '1012405') or die("Unable to connect to MySQL");
答案 1 :(得分:0)
试试吧......
$dbhandle = mysqli_connect($hostname, $username, $password, '1012405') or die("Unable to connect to MySQL");