我在php mysql中创建的注册表单有问题。我有html和php部分的表单,在db和insert查询上有连接。我需要使用_POST方法从表单中获取输入数据并将其插入db中。没有错误,它不会提交它。
这是我的代码:
<form action="registriraj.php" method="post" >
<div class="wrap-input100 validate-input m-b-23" data-validate = "Username is reauired">
<span class="label-input100">Ime:</span>
<input class="input100" type="text" name="imeregistracija" placeholder="Upišite ime">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<span class="label-input100">Prezime:</span>
<input class="input100" type="text" name="prezimeregistracija" placeholder="Upišite prezime">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input m-b-23" data-validate = "Username is reauired" style="margin-top: 20px;">
<span class="label-input100">E-mail</span>
<input class="input100" type="email" name="emailregistracija" placeholder="Upišite E-mail">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<span class="label-input100">Lozinka</span>
<input class="input100" type="password" name="passregistracija" placeholder="Upišite lozinku">
<span class="focus-input100" data-symbol=""></span>
</div>
<button type="submit" class="btn btn-outline " style="background-color:#ff6e00;margin-top: 25px;" name="submit">Registriraj korisnika</button>
</form></div></center>
PHP代码:
<?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("baza", $connection); // Selecting Database from Server
if(isset($_POST['submit'])){ // Fetching variables of the form which travels in URL
$imeregistracija = $_POST['imeregistracija'];
$prezimeregistracija = $_POST['prezimeregistracija'];
$emailregistracija = $_POST['emailregistracija'];
$passregistracija = $_POST['passregistracija'];
if($imeregistracija !=''||$passregistracija !=''){
//Insert Query of SQL
$query = "INSERT INTO `users` (`ime`, `prezime`, `user_pass`, `user_email`) VALUES ('dva','jedan','tri','cetri')";
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
mysqli_query($connection, $query);
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysql_close($connection); // Closing Connection with Server
?>
答案 0 :(得分:1)
首先检查它是否已连接到数据库。然后将$db = mysql_select_db("baza", $connection);
更改为改进版本的mysqli stmt,即$db = mysqli_select_db($connection ,"baza");
,并且您的代码不受SQL注入保护.it将帮助您
答案 1 :(得分:0)
此扩展mysql_connect and mysql_select_db
在PHP 5.5.0中已弃用,并已在PHP 7.0.0中删除。相反,应该使用MySQLi或PDO_MySQL扩展。使用mysqli_select_db()
和mysqli_connect()