单击“提交”时有两组相同的数据

时间:2017-03-08 12:22:57

标签: php mysql forms post

我想知道是否有人能够回答这个真正(可能)简单的问题。我有一个注册脚本但是当我点击“提交”时,数据会被发送两次到我的SQL数据库。以下是我的代码,非常感谢任何帮助。

$sql = "";
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$email_address = $_POST['email_address'];
$password = $_POST['password'];
$gender = $_POST['gender'];
$city = $_POST['city'];
$country = $_POST['country'];

if(isset($_POST['submit']))
{
    $sql = "INSERT INTO users (first_name, last_name, username, email_address, password, gender, city, country, verification_code, verified, sign_up_date) VALUES (
'$first_name',
'$last_name',
'$username',
'$email_address',
'$password',
'$gender',
'$city',
'$country',
'1234',
'Y',
'08/03/2017')";
    $result = mysqli_query($conn,$sql);
}

echo "
<form action='signup.php' method='post'> 
<label id='first_name'> First name</label><br/>
<input type='text' name='first_name'><br/>

<label id='last_name'> Last name</label><br/>
<input type='text' name='last_name'><br/>

<label id='username'> Username</label><br/>
<input type='text' name='username'><br/>

<label id='email_address'>E-mail Address</label><br/>
<input type='email' name='email_address'><br/>

<label id='password'>Password</label><br/>
<input type='password' name='password'><br/>

<label id='gender'>Gender</label><br />
<select name='gender'>
<option value=''>Select...</option>
<option value='M'>Male</option>
<option value='F'>Female</option>
<option value='N'>Non-binary</option>
</select><br>

<label id='city'> City</label><br/>
<input type='text' name='city'><br/>

<label id='country'> Country</label><br/>
<input type='text' name='country'><br/>

<button type='submit' name='submit'>Sign up</button>

</form>

";

0 个答案:

没有答案