刚接触PHP,一些地方还不懂,请高手指教
其实是表单的问题,不能对变量赋值<html>
<head>
<title>创建数据库</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<?php
$db_host=true;
$db_user=true;
$db_pass=true;
$db_name=true;
$message="";
if(isset($_GET["$db_host"])){
$db_host=false;
$message.="服务器名不能为空 ";
}
if(isset($_GET["$db_user"])){
$db_user=false;
$message.="数据库用户名不能为空 ";
}
if(isset($_GET["$db_pass"])){
$db_pass=false;
$message.="用户密码不能为空 ";
}
if(isset($_GET["$db_name"])){
$db_name=false;
$message.="数据库名不能为空 ";
}
?>
<body>
<table align="center">
<caption>创建数据库</caption>
<form action="sql.php">
<tr>
<td width="106">服务器名</td><td width="209"><input type="text" size="40" name="db_host" value="<?php echo $_GET["db_host"]?>"></td>
</tr>
<tr>
<td>用户</td><td><input type="text" size="40" name="db_user" value="<?php echo $_GET["db_user"]?>"></td>
</tr>
<tr>
<td>用户密码</td><td><input type="text" size="40" name="db_pass" value="<?php echo $_GET["db_pass"]?>"></td>
</tr>
<tr>
<td>数据库名</td><td><input type="text" size="40" name="db_name" value="<?php echo $_GET["db_name"]?>"></td>
</tr>
<tr>
<td> <input type="submit" name="sub" value="创建"></td>
</tr>
<?php
// if(isset($_GET["sub"])){
// if($name && $pass && $db_name){
/// $link=mysql_connect($db_host,$db_user,$db_pass)or die("连接失败".mysql_error());
// }
// else echo $message;
// if(mysql_create_db($db_name,$link))
// echo "数据库创建成功";
// else echo "chuangjianshibai";
// }
?>
<?php
if(isset($_GET["sub"])){
echo "<tr><td>";
echo $db_host;
echo "</td></tr>";
}
?>
</form>
</table>
</body>
</html>
无论输入什么都输出:1
其实是表单的问题,不能对变量赋值<html>
<head>
<title>创建数据库</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<?php
$db_host=true;
$db_user=true;
$db_pass=true;
$db_name=true;
$message="";
if(isset($_GET["$db_host"])){
$db_host=false;
$message.="服务器名不能为空 ";
}
if(isset($_GET["$db_user"])){
$db_user=false;
$message.="数据库用户名不能为空 ";
}
if(isset($_GET["$db_pass"])){
$db_pass=false;
$message.="用户密码不能为空 ";
}
if(isset($_GET["$db_name"])){
$db_name=false;
$message.="数据库名不能为空 ";
}
?>
<body>
<table align="center">
<caption>创建数据库</caption>
<form action="sql.php">
<tr>
<td width="106">服务器名</td><td width="209"><input type="text" size="40" name="db_host" value="<?php echo $_GET["db_host"]?>"></td>
</tr>
<tr>
<td>用户</td><td><input type="text" size="40" name="db_user" value="<?php echo $_GET["db_user"]?>"></td>
</tr>
<tr>
<td>用户密码</td><td><input type="text" size="40" name="db_pass" value="<?php echo $_GET["db_pass"]?>"></td>
</tr>
<tr>
<td>数据库名</td><td><input type="text" size="40" name="db_name" value="<?php echo $_GET["db_name"]?>"></td>
</tr>
<tr>
<td> <input type="submit" name="sub" value="创建"></td>
</tr>
<?php
// if(isset($_GET["sub"])){
// if($name && $pass && $db_name){
/// $link=mysql_connect($db_host,$db_user,$db_pass)or die("连接失败".mysql_error());
// }
// else echo $message;
// if(mysql_create_db($db_name,$link))
// echo "数据库创建成功";
// else echo "chuangjianshibai";
// }
?>
<?php
if(isset($_GET["sub"])){
echo "<tr><td>";
echo $db_host;
echo "</td></tr>";
}
?>
</form>
</table>
</body>
</html>
无论输入什么都输出:1
解决方案 »
- php 解析xml的问题
- 最简单的存储过程用mysql调用没问题,用mysqli调用就是不成功!!
- 整合UCHOME到现有项目实现思路
- mysql_ pconnect和mysql_connect 有什么区别呢
- 如何在调取库中数据时同时删除此条数据?(不使触发器)
- 60分 在线等 安装PHP问题
- phpmyadmin里如何管理不同用户的数据库
- 求用PHP的GD图库作饼图的程序代码?
- 为什么我在新网调试的PHP通过不了,在OSO.COM.CN却能通过?
- 求一个网址截取的正则替换表达式
- php+ajax问题
- 天啊~~~~~~~~~ PHP的时间比服务器时间(北京时间)多 20 个小时!!!!!!!!
$db_user=true;
$db_pass=true;
$db_name=true;
$message="";你这样赋值当然是1啦;$db_host='localhost';
$db_user='root';
.....
这样,根据你的数据库设置赋值
<html>
<head>
<title>创建数据库</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<?php
$db_host=true;
$db_user=true;
$db_pass=true;
$db_name=true;
$message="";
if(isset($_GET["$db_host"])){
$db_host=false;
$message.="服务器名不能为空 ";
}
if(isset($_GET["$db_user"])){
$db_user=false;
$message.="数据库用户名不能为空 ";
}
if(isset($_GET["$db_pass"])){
$db_pass=false;
$message.="用户密码不能为空 ";
}
if(isset($_GET["$db_name"])){
$db_name=false;
$message.="数据库名不能为空 ";
}
?>
<body>
<form action="sql.php" method="get">
<table align="center">
<caption>创建数据库</caption>
<tr>
<td width="106">服务器名</td>
<td width="209"><input type="text" size="40" name="db_host" value="<?php echo $_GET["db_host"];?>"></td>
</tr>
<tr>
<td>用户</td>
<td><input type="text" size="40" name="db_user" value="<?php echo $_GET["db_user"];?>"></td>
</tr>
<tr>
<td>用户密码</td>
<td><input type="text" size="40" name="db_pass" value="<?php echo $_GET["db_pass"];?>"></td>
</tr>
<tr>
<td>数据库名</td>
<td><input type="text" size="40" name="db_name" value="<?php echo $_GET["db_name"];?>"></td>
</tr>
<tr>
<td><input type="submit" name="sub" value="创建"></td>
</tr>
<?php
if(isset($_GET["sub"])){
if($name && $pass && $db_name){
$link=mysql_connect($db_host,$db_user,$db_pass)or die("连接失败".mysql_error());
}else{
echo $message;
}
if(mysql_create_db($db_name,$link)){
echo "数据库创建成功";
}else{
echo "chuangjianshibai";
}
}
if(isset($_GET["sub"])){
echo "<tr><td>";
echo $db_host;
echo "</td></tr>";
}
?>
</table>
</form>
</body>
</html>
里面的变量都付的boolean值。哈哈。