duanqiao1947 2013-12-16 19:26
浏览 64
已采纳

使用php mysql创建数据库时出错

I wrote this page to receive from a signup page. It redirects, doesn't show any error but phpmyadmin doesn't recognize the database i tried creating, i.e I can't even see the database in phpmyadmin. Whats wrong?

<html>
<body>
<?

    $con = mysql_connect_db("localhost", "user", "");
    $create_db = mysql_query('CREATE DATABASE USER', $con);
    if($create_db)
    {
        echo "wored";
    }

    $dbcreate = mysql_query('CREATE DATABASE USER',$con);
    mysql_select_db($dbcreate);

    $create = "CREATE TABLE USER1 (userid INT(20) AUTOINCREMENT NOT NULL, username VARCHAR(15) PRIMARY KEY NOT NULL, password VARCHAR(15) NOT NULL)";

    mysql_query($create);

    $query="INSERT INTO USER1(username,password) VALUES('$_POST[username]', '$_POST[password]');
    $result=mysql_query($query);

    mysql_close($con);

?>

<?php
    header('location:loginpage.html');
?>
  • 写回答

2条回答 默认 最新

  • dswu26846 2013-12-16 19:56
    关注

    You should check your PHP error logs as what you are trying to do is not even valid PHP so there is no way anything relating your database will work.

    First of all, try mysql_connect() instead of mysql_connect_db. Also make sure your database user has the correct privileges (meaning that they can actually create a database).

    Also, check your errors with mysql_error(), otherwise it will be difficult to know what failed in the database.

    Having said that, you should read up on how to submit forms with PHP and its best practices. Creating the user table after submitting the form is definitely not something you want to do. Create your table first and then insert rows into it as the users sign up. Also, you never want to store the user's password. Read up on how to use Bcrypt to save user passwords.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘