求大神帮看一下一段html和PHP连接的代码 为什么post总是为空
<!DOCTYPE HTML>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<head>
<title>PHP with MySQL</title>
</head>
<body>
<div>
<form action=submit.php method=POST>
<input name="dbname" class="dbname" value="输入要操作的数据库" onfocus="if (value =='输入要操作的数据库:如week12'){value ='';this.style.color='#000000'}" onblur="if (value ==''){value='输入要操作的数据库:如week12';this.style.color='#CCC'}" onkeydown="if(this.value=='输入要操作的数据库:如week12'){this.value='';this.style.color=#000000'}"type="text"/>
<br/>
<input name="sql" class="sql" value="输入要操作的sql语句" onfocus="if (value =='输入要操作的sql语句'){value ='';this.style.color='#000000'}" onblur="if (value ==''){value='输入要操作的语句';this.style.color='#CCC'}" onkeydown="if(this.value=='输入要操作的sql语句'){this.value='';this.style.color=#000000'}"type="text"/>
<input class="sure" name="sbtn" onclick="submit()" type="button" value="确定"/>
</form>
</div>
</body>
</html>
submit.php
<?php
header("Content-Type: text/html; charset=utf-8");
@$dbname = $_POST['dbname'];
@$sql = $_POST['sql'];
$conn = mysql_connect("localhost","root","1025");
if($dbname==null)echo "zhaobu";
$res = mysql_select_db($dbname, $conn)or die("连接数据库失败");;
$array_string = explode(' ',$sql);
if($array_string[0] == "select"){
$res = mysql_query($sql,$conn) or die("操作失败,请确认表格是否已经创建或检查指令是否出错");
Select_All($res);
}
else{
mysql_query($sql,$conn) or die("操作失败,请确认表格是否已经创建或检查指令是否出错");
}
echo "操作成功";
function Select_All($res){字数限制,此处省略}
?>
别人跑都可以我的就不行 难道是配置?要哭了简直。。。。 展开
推荐于2016-09-07 · 知道合伙人互联网行家
你的代码是正确的,可以获取到POST数据
你可以建一个123.php文件,文件大代码如下:(测试一下是否成功)
<?php
header("Content-Type: text/html; charset=utf-8");
echo <<<EOF
<form action=123.php method=POST>
<input name="dbname" class="dbname" value="" placeholder="输入要操作的数据库" onfocus="if (value =='输入要操作的数据库:如week12'){value ='';this.style.color='#000000'}" onblur="if (value ==''){value='输入要操作的数据库:如week12';this.style.color='#CCC'}" onkeydown="if(this.value=='输入要操作的数据库:如week12'){this.value='';this.style.color=#000000'}"type="text"/>
<br/>
<input name="sql" class="sql" value="" placeholder="输入要操作的sql语句" onfocus="if (value =='输入要操作的sql语句'){value ='';this.style.color='#000000'}" onblur="if (value ==''){value='输入要操作的语句';this.style.color='#CCC'}" onkeydown="if(this.value=='输入要操作的sql语句'){this.value='';this.style.color=#000000'}"type="text"/>
<input class="sure" name="sbtn" onclick="submit()" type="button" value="确定"/>
</form>
EOF;
if($_GET || $_POST){
print_r($_GET);
print_r($_POST);
}
?>
效果如图: