【问题标题】:can't insert my data to database phpmyadmin无法将我的数据插入数据库 phpmyadmin
【发布时间】:2012-08-05 18:53:39
【问题描述】:

我的代码有问题 我尝试使用 php 制作注册表单 但我无法将数据插入数据库 这是我的代码

registration_form.php 报名表格

 <body>
 <form method="post" action="register.php">
 <table border="0">

 <tr><td>username: </td><td><input type="text" name="username" /></td></tr>

 <tr><td>Password: </td><td><input type="password" name="password" /></td></tr>

 <tr><td>Confirm Password: </td><td><input type="password" name="confirm_password" /></td></tr>

 <tr><td></td><td><input type="submit" value="submit" /></td></tr>

 </table>
 </form>
 </body>
 </html>

注册.php

 $con=mysql_connect("localhost","root","");
 /* Now, we select the database */
 mysql_select_db("login&register");

 /* Now we will store the values submitted by form in variable */
 $username=$_POST['username'];
 $pass=$_POST['password'];
 /* we are now encrypting password while using md5() function */
 $password=md5($pass);
 $confirm_password=$_POST['confirm_password'];

 /* Now we will check if username is already in use or not */
 $queryuser=mysql_query("SELECT * FROM register WHERE username='$username' ");
 $checkuser=mysql_num_rows($queryuser);
 if($checkuser != 0)
 { echo "Sorry, ".$username." is already been taken."; }
 else {

 /* now we will check if password and confirm password matched */
 if($pass != $confirm_password)
 { echo "Password and confirm password fields were not matched"; }
 else {

 /* Now we will write a query to insert user details into database */
 $insert_user=mysql_query("INSERT INTO register (username, password) VALUES ('$username',     '$password')");

 if($insert_user)
 { echo "Registration Succesfull"; }
 else
 { echo "error in registration".mysql_error(); }

 /* closing the if else statements */
 }}

 mysql_close($con);
 ?>

当我点击提交按钮时出现错误消息

 Object not found!

 The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

 If you think this is a server error, please contact the webmaster.

 Error 404

 localhost
 08/08/12 23:46:37
 Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1

请帮我解决这个问题 谢谢

【问题讨论】:

  • 强制提及您的代码易受 sql 注入攻击。更多信息:php.net/manual/en/security.database.sql-injection.php
  • 另外值得一提的是,有许多可用于 PHP 的框架可以消除向应用程序添加身份验证的所有痛苦。为什么要重新发明轮子?
  • 我真的不明白...
  • Mansfield 的意思是,使用您编写的代码将意味着任何人都可以侵入您的网站,删除您的所有用户信息,甚至更糟。谷歌 SQL 注入攻击了解更多信息。我建议使用像 Yii 这样的 PHP 框架(它提供了一个开箱即用的登录系统)将比你自己编写的任何东西都更加可靠、稳定和安全。
  • 我明白了……嗯,我的程序已经可以运行了……谢谢你的建议 :)

标签: php html database phpmyadmin registration


【解决方案1】:
<form method="post" action="register.php">

您的 PHP 文件似乎名为 registration.php

【讨论】:

  • @BudiCzras - 您收到 404 错误,这意味着您要查找的页面不存在。你确定这两个在同一个目录中吗?
【解决方案2】:

您的表单操作是register.php,但您的 php 文件名为 registration.php,请将您的表单操作更改为 registration.php

【讨论】:

    【解决方案3】:

    您正在尝试访问表单中的register.php 而不是registration.php

    【讨论】:

      【解决方案4】:

      这看起来不像是数据库问题。而是找不到 register.php。您已将文件保存为 registration.php。

      【讨论】:

      猜你喜欢
      • 2013-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 2017-03-17
      • 2016-03-29
      • 2019-06-29
      • 2012-04-13
      相关资源
      最近更新 更多