-1

I have problem with register form created in php mysql. I have form in html and php part with connection on db and insert query. I need to get input data from the form with _POST method and insert that in db. There are no errors it just wont submit it.

Here is my code:

<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="&#xf206;"></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="&#xf206;"></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="&#xf206;"></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="&#xf190;"></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 code:

<?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
?>
chris85
  • 23,846
  • 7
  • 34
  • 51
Zeljo
  • 25
  • 1
  • 7

2 Answers2

1

first check it are you connected to database.Then change $db = mysql_select_db("baza", $connection); to improved version of mysqli stmt i.e $db = mysqli_select_db($connection ,"baza"); and your code not SQL injection protected .it will help you

Akshay Parate
  • 185
  • 1
  • 10
0

This extension mysql_connect and mysql_select_db was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. Use mysqli_select_db() and mysqli_connect()

Aliaksandr Sushkevich
  • 11,550
  • 7
  • 37
  • 44
Owais Noor
  • 134
  • 10
  • Now everything works but when I click submit button user is registered and then form is clear. I press F5 to refresh page and it insert data from last input i dont know why – Zeljo Apr 21 '18 at 16:34
  • Yes, That is the problem with php...Do One thing...Once you submit your form reload the page by using header('location:'yourFprmPage.php'); – Owais Noor Apr 21 '18 at 16:48