简体   繁体   English

PHP用表格注册,数据输入数据库

[英]PHP sign up with form, data entered into database

I have an admin portion of my website and would like to have the functionality of allowing admins to sign up and then be able to login. 我有我的网站的管理员部分,并希望具有允许管理员注册然后能够登录的功能。 Right now I'm working on the Sign up form. 现在我正在处理注册表单。 When I submit my username and password, the web browser just shows a blank screen and nothing is added into my database. 当我提交用户名和密码时,Web浏览器只显示一个空白屏幕,并且没有任何内容添加到我的数据库中。 Here is my code. 这是我的代码。 Any ideas why this is happening, and not working? 任何想法为什么会这样,而不是工作?

<?
$con = mysql_connect("localhost", "root", "");
if(!$con)
    {
    die('Could not connect: ' .mysql_error());
    }
mysql_select_db("bics_place", $con);

$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 
$encrypted_mypassword=md5($mypassword);

$sql = "INSERT INTO admin
            (username, password)
            VALUES
            ('myusername','encrypted_mypassword')";

if(!mysql_query($sql, $con))
    {
    die('Error: ' .mysql_Error());
    }
echo "1 record added";

mysql_close($con);

?>

I tested your code locally, it works. 我在本地测试了你的代码,它有效。 A couple things to check. 要检查几件事。

It's possible your server isn't configured to allow short tags. 您的服务器可能未配置为允许短标签。 Try changing '<?' 尝试更改'<?' in line 1 to '<?php' . 在第1行到'<?php'

If you must use short tags (you are working with someone else' code who uses them), you'll need to edit your php.ini file to allow it. 如果你必须使用短标签(你正在使用其他人使用它们的代码),你需要编辑你的php.ini文件以允许它。 I tend to avoid them for compatibility reasons. 出于兼容性原因,我倾向于避开它们。

short_open_tag=On

Should that not resolve your issue, add error_reporting(E_ALL); 如果这不能解决您的问题,请添加error_reporting(E_ALL); to the beginning of your file and it should show you the error. 到文件的开头,它应该显示错误。 Remove it once you have your code working. 一旦代码正常工作,请将其删除。

Also, you will need to edit your $sql variable. 此外,您还需要编辑$ sql变量。 Put $ in front of your variable names. 将$放在变量名前面。

$sql = "INSERT INTO admin
        (username, password)
        VALUES
        ('$myusername','$encrypted_mypassword')";

Otherwise, what does your server error log tell you? 否则,您的服务器错误日志会告诉您什么?

Not sure why you wouldn't see any errors but your SQL is incorrect. 不确定为什么你不会看到任何错误,但你的SQL不正确。

You have: 你有:

$sql = "INSERT INTO admin (username, password) VALUES ('myusername','encrypted_mypassword')";

Which should be: 应该是:

$sql = "INSERT INTO admin (username, password) VALUES ('$myusername','$encrypted_mypassword')";

You're missing the $ in front of your variables. 你错过了变量前面的$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM