PHP MySQL 注册表格不工作,没有错误
PHP MySQL Register form isnt working, no errors
我在 php mysql 中创建的注册表单有问题。我在 html 和 php 部分中有表格与数据库连接并插入查询。我需要使用 _POST 方法从表单中获取输入数据并将其插入到数据库中。没有错误只是不会提交。
这是我的代码:
<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
?>
首先检查您是否连接到 database.Then 将 $db = mysql_select_db("baza", $connection);
更改为 mysqli stmt 的改进版本,即 $db = mysqli_select_db($connection ,"baza");
并且您的代码没有 SQL 注入保护。它会有所帮助你
此扩展 mysql_connect and mysql_select_db
在 PHP 5.5.0 中已弃用,并在 PHP 7.0.0 中删除。相反,应该使用 MySQLi 或 PDO_MySQL 扩展。使用 mysqli_select_db()
和 mysqli_connect()
我在 php mysql 中创建的注册表单有问题。我在 html 和 php 部分中有表格与数据库连接并插入查询。我需要使用 _POST 方法从表单中获取输入数据并将其插入到数据库中。没有错误只是不会提交。
这是我的代码:
<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
?>
首先检查您是否连接到 database.Then 将 $db = mysql_select_db("baza", $connection);
更改为 mysqli stmt 的改进版本,即 $db = mysqli_select_db($connection ,"baza");
并且您的代码没有 SQL 注入保护。它会有所帮助你
此扩展 mysql_connect and mysql_select_db
在 PHP 5.5.0 中已弃用,并在 PHP 7.0.0 中删除。相反,应该使用 MySQLi 或 PDO_MySQL 扩展。使用 mysqli_select_db()
和 mysqli_connect()