我想要一个select count语句从表行中检索值,并使用php验证它对另一个表行。 意思
Hello Guys / Gurus 请问我有问题,我需要几个月才能使用php,我需要你的帮助/帮助。 这就是流程。客户在另一个站点注册,当我们确认注册时,我们会向他们发送一个代码。 代码生成并保存在另一个名为code和column generated_code的表名中。
我开发了一个表单(http://cash2money2020.com/form.html) 所以我想要的是,如果有人输入我们发送给他们的生成代码,并在表单中填写它,它会使数据库检查以查看代码是否存在于另一个表中,如果是,则提交表单..如果没有,则错误消息,代码无效,表单将不会提交:
$query = "INSERT INTO registration
(id, fname, lname, address1, address2, city, state, country, email, phone, home_phone, dob, gender, living, qualification, mental, mental_details, criminal, criminal_details, kin_name, kin_phone, kin_relationship, tv_appearance, work_financial, tv_station, why, interesting, impressive, generated_code, submitted_date)
VALUES
('', '$fname', '$lname', '$address1', '$address2', '$city', '$state', '$country', '$email', '$phone', '$home_phone', '$dob', '$gender', '$living', '$qualification', '$mental', '$mental_detail', '$criminal', '$criminal_details', '$kin_name', '$kin_phone', '$kin_relationship', '$tv_appearance', '$work_financial', '$tv_station', '$why', '$interesting', '$impressive', '$code', now()) ";
这是我到目前为止所做的事情
$result = mysqli_query("select count(generated) from code ");
if (!$result) echo mysqli_error();
$row = mysqli_fetch_row($result);
$query = "INSERT INTO registration (generated_code) VALUES ('$code')";
if ($query != $row) {
//code to submit and process the form
}
else
{
//error message
}
请帮助我坚持!!!
答案 0 :(得分:0)
这样的事情应该做(根据最后的评论):
$link = mysqli_connect("my_host", "my_user", "my_password", "my_db");
$result = mysqli_query($link, "select * from code where generated = '$code'");
if (!$result) die("mysql error: " . mysqli_error());
$row = mysqli_fetch_row($result);
if ( $row !== false ) {
// code to submit and process the form
// you might use the result with $row[<fieldname>]
}
else
{
// error message
}
您需要添加一些错误处理和非转义值(例如$code
)