gpt4 book ai didi

php - 无法选择表并同时向其中插入内容(Mysql)

转载 作者:行者123 更新时间:2023-11-30 22:54:06 25 4
gpt4 key购买 nike

我有这个注册表,当用户完成表单时,他最终会提交它,但我想检查用户名和电子邮件是否已经存在,很容易吧?已经花了 2 天时间试图解决这个问题,但没有运气。对不起,我没有使用最新版本的 MySQL,因为这是我在类里面学到的唯一版本。我会学习改进的。

我在 Google 上做了很多研究,我发现这是 LOCK 之王,当我们插入表时会被锁定..

if(isset($_POST['button'])){


$query_global = mysql_query("SELECT Username FROM users WHERE Username = '".$_POST['username']."' ") or die(mysql_error());

$row = mysql_num_rows($query_global);

if($row == 1){
$error_username = "The username is already registered, please choose another one <br>";
}

$query_email = mysql_query("SELECT Email FROM users WHERE Email = '".$_POST['email']."' ") or die(mysql_error());

$row_email = mysql_num_rows($query_email);

if($row_email == 1){
$error_email = "This email : '".$_POST['email']."' is already registered ";
}

if(isset($_POST['Username'])) { $Username = $_POST['Username']; }
if(isset($_POST['email'])) { $email = $_POST['email']; }



$nom = $_POST['nom'];
$sexe = $_POST['sexe'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$adresse = $_POST['adresse'];
$ville = $_POST['ville'];
$pseudo = $_POST['pseudo'];
$mdp = $_POST['mdp'];
$date = $_POST['date'];
$profession = $_POST['profession'];


// location where initial upload will be moved to
$target = "images/" .$_FILES['uploaded']['name'] ;

// find thevtype of image
switch ($_FILES["uploaded"]["type"]) {
case $_FILES["uploaded"]["type"] == "image/gif":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/jpeg":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/pjpeg":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/png":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;
case $_FILES["uploaded"]["type"] == "image/x-png":
move_uploaded_file($_FILES["uploaded"]["tmp_name"],$target);
break;

default:
$error[] = 'Seulement les JPG, PNG ou GIF sont acceptés!.';
}

$error="";

if (!$error) {

$query = "INSERT INTO Users Values ('', '".$nom."', '".$sexe."', '".$email."', ".$tel.", '".$adresse."', '".$ville."', '".$pseudo."', '".$mdp."', curdate(), '$target', '".$date."', '".$profession."')";
$add_user = mysql_query($query) or die(mysql_error());

header('Location: Login/index.php');

}

}


//display any errors
if (!empty($error))
{
$i = 0;
echo "<p><span class='error'>";
while ($i < count($error)){
echo $error[$i].'<br />';
$i ++;}
echo "</span></p>";
}

即使所有这些都成功了,当输入错误时是否有任何方法可以阻止表单提交,我的意思是我已经在另一个文件中尝试过它并且它有效但即使输入错误表单也会被提交。

迫不及待想听听您的回答。

最佳答案

您没有任何东西可以阻止脚本运行

if($row_email == 1){
$error_email = "This email : '".$_POST['email']."' is already registered ";
}
else{

//all the rest of your code here

}

在不确定其目的是什么之前,您将 $error 设置为任何错误:

$error="";

if (!$error) {

关于php - 无法选择表并同时向其中插入内容(Mysql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27139939/

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