不能插入我的数据到数据库phpmyadmin

k3bvogb1  于 2022-11-09  发布在  PHP
关注(0)|答案(4)|浏览(161)

我得到了一个问题,在我的代码我试图使一个注册表使用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>

register.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

请帮我解决这个问题谢谢

js5cn81o

js5cn81o1#

<form method="post" action="register.php">

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

bnl4lu3b

bnl4lu3b2#

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

wr98u20j

wr98u20j3#

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

ipakzgxi

ipakzgxi4#

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

相关问题