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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?