gpt4 book ai didi

Php表单提交-报错

转载 作者:行者123 更新时间:2023-12-01 00:45:13 28 4
gpt4 key购买 nike

<?php

include ("db.php");

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

echo $name = ($_POST["name"]);
echo $email = ($_POST["email"]);
echo $uname = ($_POST["uname"]);
echo $password = ($_POST["pass"]);


$result = mysql_query($con,'SELECT * from company_profile where user_name = "'.$uname.'" or email = "'.$email.'"');
if(mysql_num_rows($result) > 0){
echo "Username or email already exists.";
}else{
$query = mysql_query($con,"INSERT INTO company_profile(user_name, password, company_name, email, phone, country, activation_string) VALUES ('$uname','$password','$name','$email','','','')");

if($query){
echo "data are inserted succesfully.";
}else{
echo "failed to insert data.";
}
}

}


?>

HTML 格式

<form action="register.php" method="post" id="reg" onsubmit='return validate();'>
Company Name: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" class="inputs" name="name" id="name" /><br />
Email: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" class="inputs" name="email" id="txtEmail" /><br />
User name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" class="inputs" name="uname" id="uname"/><br />
Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="password" class="inputs" name="pass" id="pass1"/><br />
Conferm Password: &nbsp;&nbsp;&nbsp;
<input type="password" class="inputs" name="cpass" id="pass2"/><br /><br />
<input type="submit" value="Register" class="button" />
</form>

尝试检查数据库中是否存在用户名或电子邮件,如果存在则提醒用户,如果不存在则向数据库插入值。该代码对我不起作用。没有错误没有 echo 没有插入。有什么解决办法吗?

最佳答案

您没有名称为 register 的字段

对此

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

它永远不会计算为真。

<input type="submit" value="Register" class="button" />

需要名称属性name="register"

另外:

http://php.net/mysql_query

你的参数顺序错误。但是,强烈不鼓励使用 mysql_*。它是一个过时的数据库 API,存在很多漏洞。改用 mysqli 或 PDO

关于Php表单提交-报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23012067/

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