我仍然不熟悉从带有php的html网页表格到数据库的POSTING,但我想我已经能够拼凑出我需要的一切。但是仍然缺少某些东西,我不知道是什么。
我测试了我的连接和表格:
<?php
$link = mysqli_connect("localhost","#user","#password", "#database");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
$test_query = "SHOW TABLES FROM" $#database;
$result = mysqli_query($connect, $test_query);
$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
mysqli_close($link);
?>
我尝试过127.0.0.1并且访问主机IP(RemoteMySQL)无济于事。我的用户拥有完全权限。我不知道任何其他可能妨碍我的默认安全性。
我使用MySQL和phpmyadmin托管Bluehost。我的数据库中有2个表,当我在phpmyadmin中输入“SHOW TABLES”时会找到它们。我错过了什么?这是我所不知道的。我的智慧结束了......
非常感谢你!
答案 0 :(得分:0)
我在这一行中看到了一些问题。
$test_query = "SHOW TABLES FROM" $#database; // Line 10
您没有任何名为$ database的变量。并且您的符号#不正确。 #用于评论(http://php.net/manual/en/language.basic-syntax.comments.php)
FROM之后缺少空间。这一行应该是
$test_query = "SHOW TABLES FROM " . $database;
否则,生成的查询将是“SHOW TABLES FROMDATABASE_NAME”,这将触发SQL错误。
此外,在while循环后缺少大括号。这是完整的代码更正。
<?php
$link = mysqli_connect("localhost","#user","#password", "#database");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db
database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
$database = "YOUR_DATABASE_NAME_HERE";
$test_query = "SHOW TABLES FROM " . $database;
$result = mysqli_query($link, $test_query);
$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
$tblCnt++;
}
// echo $tbl[0]."<br />\n";}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
mysqli_close($link);
?>
我希望它有所帮助。