dqbhdsec59405 2012-09-19 20:31
浏览 12

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

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. 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);

?>
  • 写回答

2条回答 默认 最新

  • dongyi9484 2012-09-19 20:35
    关注

    Not sure why you wouldn't see any errors but your SQL is incorrect.

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)