gpt4 book ai didi

PHP注册表格与mysql

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:38 25 4
gpt4 key购买 nike

我已经用 php 和 mysql 制作了一个注册表。只有在每次都引入不同的用户名时它才有效。我怎样才能解决这个问题?因为有时我想在数据库中插入相同的名称。

我的代码:

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

最佳答案

用于检查用户名是否存在

<?php
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'];

$chk_query = mysql_query("Select (username) from user where username=$username");
$num = mysql_num_rows($chk_query);

if($num < 1)
{
$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);
}
else { echo "User name exist"; }
}

?>

关于PHP注册表格与mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36911562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com