douwen9540 2016-04-28 10:13
浏览 27
已采纳

Php注册表单与mysql

I have made a register form with php and mysql. It works only if it is introduced diffrent name of user each time. How can i rezolve that? because sometimes i want to insert the same name in the database.

My code:

require('connect.php');
if (isset($_POST['adresa'])) {
    $username = $_POST['username'];
    $email = $_POST['email'];
    $adresa = $_POST['adresa'];
    $judet = $_POST['judet'];
    $telefon = $_POST['telefon'];
    $localitate = $_POST['localitate'];
    $bon = $_POST['bon'];
    $date = $_POST['date'];
    $premiu = $_POST['premiu'];
    $query = "INSERT INTO user (username, adresa, email,judet,telefon,localitate,bon,date,premiu,acord) VALUES ('$username', '$adresa', '$email','$judet','$telefon','$localitate','$bon','$date','$premiu','$acord')";
    $result = mysql_query($query);
}
  • 写回答

2条回答 默认 最新

  • dsplos5731 2016-04-28 10:28
    关注

    If you can't insert multiple users with the same name to the database then the username field must have been flagged as UNIQUE at table declaration.

    To remove this restriction use DROP INDEX

    Note that, if the username field is a primary key you will need to drop the primary key and introduce another, a BIGINT for example (Best option).

    IMPORTANT : mysql_ functions are deprecated and you should stop using them. Use mysqli_ or PDO instead

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

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM