我对 PHP 很陌生,还有很长的路要走。可能是逻辑故障,或者我只是不知道 PHP 究竟是如何工作的。无论如何,我提交的代码来自我的管理控制面板。我正在尝试创建一个页面来连接到数据库,而不是显示所有数据库名称并从单选按钮中选择其中一个。当再次按下提交以显示表格时。显示表格后,下一步将是编辑,添加更新它们等。我还没有。因为我无法让 mysql_select_db 工作。它给出了错误。错误是;
注意:未定义的变量:在第 94 行的 /public_html/php/insert_delete_update_amend/mydata03.php 中连接
警告:mysql_select_db():提供的参数不是第 94 行 /public_html/php/insert_delete_update_amend/mydata03.php 中的有效 MySQL-Link 资源无法连接到 db
任何帮助都感激不尽。PS:同样,当第一个表单提交时,第一个表单消失,第二个出现,依此类推。
<?php
// form variables
$DisplayDBinfoForm = true;
$DisplayDBform = false;
if (isset($_POST['db_info_submit'])) { //when user presses db info submit button
//select which form to hide or appear
$DisplayDBinfoForm = false;
$DisplayDBform = true;
$hostname = $_POST['db_name'];
$db_user_name = $_POST['db_user_name'];
$db_user_password = $_POST['db_user_password'];
$connect = mysql_connect($hostname,$db_user_name,$db_user_password);
if(!$connect) die("Could not connect");
echo "<p><b>connected successfully</b></p>\n";
}
if($DisplayDBinfoForm) {
?>
<form name="dbinfo" method="POST" action="mydata03.php" onsubmit="return validateForm();">
Host Name: <input type="text" name="db_name" /><br />
<br />
DB User Name <input type="text" name="db_user_name" /><br />
<br />
DB User Password: <input type="text" name="db_user_password" /><br />
<br />
<input type="submit" name="db_info_submit"value="Login"><br />
</form>
<?php
}
if($DisplayDBform) {
?>
<form name="delete_table" id="delete_table" action="mydata03.php" method="post">
<table width="30%" border="1">
<tbody>
<?php
$query = "SHOW DATABASES";
$resultSet = mysql_query($query);
while($database = mysql_fetch_array($resultSet)) { // go through each row that was returned in $result
$dbname = $database[0];
echo "<tr><th>Database Name</th>
<th>Select</th>
</tr>
<tr>
<td>$dbname</td>
<td><input name=\"radDB\" id=\"radDB\" type=\"radio\" value=\"$dbname\"</td>
</tr>\n";
}
?>
</tbody>
</table>
<p>
<input name="btnSelectDB" type="submit" value="Select" />
</form>
</p>
<?php
}
if(isset($_POST['btnSelectDB'])) {
$DisplayDBinfoForm = false; // hide form
$DisplayDBform = false; // hide form
$db_name = $_REQUEST["radDB"]; // the db na,e
echo "The " . $db_name . " is selected\n";
$select_db = mysql_select_db($db_name,$connect);
if(!$select_db) die("Could not connect to db". mysql_error());
echo "<b>connected successfully to db</b>";
}
?>