日期:2014-05-17  浏览次数:20604 次

if(isset($_POST['submit']))无法执行
<form name="adduser" action="dealadduser.php" method="POST">
  添加管理员<br>
  姓 名: <input type="text" name="username"></br>
  密 码: <input type="password" name="password"></br>
  <input type="submit" name="submit" value="提交"/>
  <input type="reset">

</form>

<?php

if(isset($_POST['submit']))
  {  
 
  mysql_connect("localhost","root","");
  mysql_select_db("soft");
  mysql_query("set character set gbk");
  $username=$_POST["username"];
  $password=$_POST["password"];
  $sql="insert into `users`(`name`,`pass`) values ('$username','$password')";
  echo $sql;
  mysql_query($sql);  
  mysql_close();
  
  }
?>



点提交一直无法写入数据库,if(isset($_POST['submit']))根本不执行?求教

------解决方案--------------------
测试过你的代码是没有问题的,除非你这个页不是dealadduser.php

PHP code
<form name="adduser" action="" method="POST">//如1楼说的直接本页
  添加管理员<br>
  姓 名: <input type="text" name="username"></br>
  密 码: <input type="password" name="password"></br>
  <input type="submit" name="submit" value="提交"/>
  <input type="reset">

</form>

<?php

if(isset($_POST['submit']))
  {   
 
  mysql_connect("localhost","root","");
  mysql_select_db("soft");
  mysql_query("set character set gbk");
  $username=$_POST["username"];
  $password=$_POST["password"];
  $sql="insert into `users`(`name`,`pass`) values ('$username','$password')";
  echo $sql;
  mysql_query($sql);   
  mysql_close();
   
  }
?>

------解决方案--------------------
难道你的本页不是dealadduser.php页吗?
如果不是,dealadduser.php页应该是
PHP code
<?php

if(isset($_POST['submit']))
  {   
 
  mysql_connect("localhost","root","");
  mysql_select_db("soft");
  mysql_query("set character set gbk");
  $username=$_POST["username"];
  $password=$_POST["password"];
  $sql="insert into `users`(`name`,`pass`) values ('$username','$password')";
  echo $sql;
  mysql_query($sql);   
  mysql_close();
   
  }
?>