我正在自学MySQL和PHP,所以请耐心等待。我正在尝试设置一个数据库,其值通过PHP表单输入。我正在读一本书,但找不到我收到错误的原因:
连接MySQL服务器时出错。
我正在运行本地主机,root用户名,无密码和名为alien_abductions
的表。
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_happened = $_POST['whenithappened'];
$how_long_gone = $_POST['howlongwereyougone'];
$howmany = $_POST['howmany'];
$description = $_POST['description'];
$whattheydid = $_POST['whattheydid'];
$fangspotted = $_POST['fangspotted'];
$email = $_POST['email'];
$dbc = mysqli_connect('localhost', 'root', '', 'up_amd_running')
or die('Error connecting to MySQL server');
$query = "INSERT INTO alien_abductions (first_name, last_name, " .
"when_happened, how_long_gone, howmany, description, " .
"whattheydid, fangspotted, email " .
"VALUES ('$first_name', '$last_name',
'$when_happened','$how_long_gone', '$howmany', '$description',
'$whattheydid', `'$fangspotted', '$email')";
echo $query;
$result = mysqli_query($dbc, $query)
or die('Error querying database');
mysqli_close($dbc);