I have this code
我有这个代码
<form action="" method="POST">
PIN:
<input type="text" name="pin"><br />
E-Mail:
<input type="text" name="email"><br />
<input type="submit" value="Claim" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['pin']) && !empty($_POST['email'])) {
$pin=$_POST['pin'];
$email=$_POST['email'];
$con=mysql_connect('localhost','root','admin') or die(mysql_error());
mysql_select_db('user_codevalidation') or die("cannot select DB");
$sql="INSERT INTO codes(email) VALUES('$email') WHERE pin='".$dbpin."'";
mysql_query($sql);
echo "Successfully claimed!";
{
while($row=mysql_fetch_assoc($query))
{
$dbpin=$row['pin'];
}
if($pin == $dbpin)
{
$sql="INSERT INTO codes(email,claimed) VALUES('$email','1') WHERE pin = $dbpin";
echo "Successfully claimed!";
}
} else {
echo "Invalid pin or it has already been claimed once!";
}
} else {
echo "All fields are required!";
}
}
?>
I want to be able to validate pin
AND if claimed = 0 in the database in the row $pin
where pin
is equal to the value in pin textbox $pin
, if it is equal, then execute $sql
which is to insert the value in email into the sql $email
which is the email textbox, and then change the claimed
value to '1' which is by default 0 in the database.
我希望能够验证引脚AND如果在$ pin行的数据库中声明= 0,其中pin等于pin textbox $ pin中的值,如果它相等,则执行$ sql,即插入值通过电子邮件发送到sql $ email这是电子邮件文本框,然后将声明的值更改为“1”,默认情况下为0。
I got everything working and it says 'Successfully claimed!' but it does not change my values in the database. Please help!
我把一切都搞定了,并说“成功声称!”但它不会改变我在数据库中的值。请帮忙!
Edit: I have added the execute MySQL query and it still gives me the same result!
编辑:我添加了执行MySQL查询,它仍然给我相同的结果!
3 个解决方案
#1
1
There is no query execution command mysql_query() Add this line after the query
没有查询执行命令mysql_query()在查询后添加此行
mysql_query($sql);
#2
0
You need to make sure you execute the query:
您需要确保执行查询:
mysql_query($sql);
#3
0
you need to execute the query
你需要执行查询
Edit I added some lines in order to debug your query. Please copy & paste and tell me if you see any error.
编辑我添加了一些行以调试您的查询。如果您发现任何错误,请复制并粘贴并告诉我。
PIN:E-Mail:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
if(isset($_POST["submit"])){
if(!empty($_POST['pin']) && !empty($_POST['email'])) {
$pin=$_POST['pin'];
$email=$_POST['email'];
$con=mysql_connect('localhost','root','admin') or die(mysql_error());
mysql_select_db('user_codevalidation') or die("cannot select DB");
$query=mysql_query("SELECT * FROM codes WHERE pin='".$pin."'");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbpin=$row['pin'];
}
if($pin == $dbpin)
{
$sql="INSERT INTO codes(email,claimed) VALUES('".$email."','1') WHERE pin = '".$dbpin."'";
$res = mysql_query($sql) or die(mysql_error());
echo "Successfully claimed!";
}
} else {
echo "Invalid pin or it has already been claimed once!";
}
} else {
echo "All fields are required!";
}
}
?>
#1
1
There is no query execution command mysql_query() Add this line after the query
没有查询执行命令mysql_query()在查询后添加此行
mysql_query($sql);
#2
0
You need to make sure you execute the query:
您需要确保执行查询:
mysql_query($sql);
#3
0
you need to execute the query
你需要执行查询
Edit I added some lines in order to debug your query. Please copy & paste and tell me if you see any error.
编辑我添加了一些行以调试您的查询。如果您发现任何错误,请复制并粘贴并告诉我。
PIN:E-Mail:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
if(isset($_POST["submit"])){
if(!empty($_POST['pin']) && !empty($_POST['email'])) {
$pin=$_POST['pin'];
$email=$_POST['email'];
$con=mysql_connect('localhost','root','admin') or die(mysql_error());
mysql_select_db('user_codevalidation') or die("cannot select DB");
$query=mysql_query("SELECT * FROM codes WHERE pin='".$pin."'");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbpin=$row['pin'];
}
if($pin == $dbpin)
{
$sql="INSERT INTO codes(email,claimed) VALUES('".$email."','1') WHERE pin = '".$dbpin."'";
$res = mysql_query($sql) or die(mysql_error());
echo "Successfully claimed!";
}
} else {
echo "Invalid pin or it has already been claimed once!";
}
} else {
echo "All fields are required!";
}
}
?>