[英]No database selected error php mysql
i have created a database in phpmyadmin. 我已经在phpmyadmin中创建了一个数据库。 When I submit the form, the script is supposed to insert data in the database.
当我提交表单时,该脚本应该在数据库中插入数据。 However, i get the error "No database selected".
但是,我收到错误“未选择数据库”。 Could you please look at my code and see if you can find where I went wrong.
您能否看一下我的代码,看看是否能找到我出错的地方。 Thank you
谢谢
$dbc = mysqli_connect('localhost','aliendatabase') or die('Error connecting to MySQL server.');
$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, ".
"how_many, alien_description, what_they_did, fang_spotted, other, email) " .
"VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";
$result = mysqli_query($dbc, $query)
or die(mysqli_error($dbc));
mysqli_close($dbc);
Correct Syntax is 正确的语法是
mysqli_connect('host','username', 'password', 'database_name');
Read manual :- http://in2.php.net/manual/en/function.mysqli-connect.php 阅读手册: -http : //in2.php.net/manual/zh/function.mysqli-connect.php
For localhost without password 对于没有密码的本地主机
mysqli_connect('localhost','root', '', 'database_name');
您必须在mysqli_connect
之后使用mysqli_select_db('your_database_name');
选择数据库mysqli_select_db('your_database_name');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.