我在使用php脚本注册表单时遇到问题,我检查了很多关于这类问题的帖子,而我仍然没有得到它...我正在尝试自己编写代码将用户插入数据库客人试图注册新用户后..
我写了这样的代码,我知道它不应该是那样的,但我自己尝试学习一些东西,如果你们可以帮助我提供你的专业技巧我应该添加什么以及我应该删除什么制作安全可靠的代码
我编写的PHP代码
<?php
include("dbconnect.php");
if (!isset($_POST['registracija'])); {
$uporabnik = $_POST['uporabnik']; #----------- Username ------------#
$email = $_POST['email'];#----------- Email ------------#
$geslo = $_POST['geslo'];#----------- Password ------------#
$geslo2 = $_POST['geslo2'];#----------- Confirm password ------------#
$spol = $_POST['spol']; #----------- Gender ------------#
if($geslo == $geslo2){ #----------- Password / password confirm ------------#
$msg = 'gesli se ujemata'; #----------- Passwords are same ------------#
} else {
$msg = 'gesli se ne ujemata'; #----------- Error confirm password ------------#
}
}
if (strcmp ($uporabnik, $email, $geslo, $geslo2, $spol) == 0) {
$sql = "INSERT INTO uporabniki (uporabnik, email, geslo, spol)
VALUES ('$uporabnik', '$email', '$geslo', '$spol')";
if (mysqli_query($conn, $sql)) {
echo "Registered Successfully!";
}
}
?>
这里是注册表格的html版本
<form method="Post" >
<?php if(isset($msg)) echo $msg; ?><br>
<label >Uporabniško ime</label>
<input type="text" name="uporabnik" placeholder="Username..." size="50" required/>
<br>
<label >Email</label>
<input type="email" name="email" placeholder="Email" size="50" required/>
<br>
<label>Spol</label>
<input type="radio" name="spol" value="moški" required> Moški
<input type="radio" name="spol" value="ženska" required> Ženska
<br>
<label>Geslo</label>
<input type="password" name="geslo" placeholder="Password..." size="50" required/>
<br>
<label >Ponovi geslo</label>
<input type="password" name="geslo2" id="geslo2" placeholder="Confirm password..." size="50" required/>
<input type="submit" name="registracija" id="registracija" value="Registracija">
</form>
我希望你们不会评判我,你们会帮助我,所以我可以学到更多...我是新来的 感谢您的时间和提示!