First of all, I was googling it for over 4 hours. Found dozen of similar questions even here on stackoverflow, but I really couldnt find the solution. So thats why im writing new question.. im pretty much a newbie, and i really tried everything I could on my own and with the answers I found here, but nothing seems to be working. Btw, sorry for my broken english..
so here are my errors when i try to submit my new user registration inputs to the database:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\epo\insert.php on line 17
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\epo\insert.php on line 18
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\epo\insert.php on line 28
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\epo\insert.php on line 29
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\epo\insert.php on line 30
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\epo\insert.php on line 31
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\epo\insert.php on line 36
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\epo\insert.php on line 39
Neuspesno upisivanje u bazu podataka!
here is the db connection code (konekcija.php) :
<?php
ob_start();
if(!isset($_SESSION)){
session_start();
}
$host = 'localhost';
$user = 'root';
$pass = '';
$db_name = 'epo';
$connection = mysqli_connect($host, $user, $pass, $db_name);
if(!$connection){
die("CONNECTION TO DB FAILED. " . mysqli_error($connection));
}
?>
here's the registration form (reg.php) file :
<?php include("insert.php"); ?>
<?php include("index.php");?>
<div class="container">
<div class="row" style="text-align:center;">
<h3>Registarcija korisnika za EPO sistem</h3>
</div>
<div class="row registracija">
<div class="row">
<h3>Dobrodosli, molimo Vas, popunite polja kako biste se registrovali.</h3>
</div>
<form action="" method="post" class="form-horizontal">
<?php echo $errordanger; ?>
<?php echo $uspehreg; ?>
<div class="row form-group inputgrp">
<label for="" class="col-sm-2">Ime: </label>
<div class="col-sm-10">
<input type="text" name="ime" id="ime" class="form-control">
</div>
</div>
<form action="" method="post" class="form-horizontal">
<div class="row form-group inputgrp">
<label for="" class="col-sm-2">Prezime: </label>
<div class="col-sm-10">
<input type="text" name="prezime" id="prezime" class="form-control">
</div>
</div>
<form action="" method="post" class="form-horizontal">
<div class="row form-group inputgrp">
<label for="" class="col-sm-2">E-mail: </label>
<div class="col-sm-10">
<input type="text" name="email" id="email" class="form-control">
</div>
</div>
<form action="" method="post" class="form-horizontal">
<div class="row form-group inputgrp">
<label for="" class="col-sm-2">Sifra: </label>
<div class="col-sm-10">
<input type="password" name="password" id="password" class="form-control">
</div>
</div>
<form action="" method="post" class="form-horizontal">
<div class="row form-group" style="margin: 0px 10px 20px 10px">
<div class="col-xs-12">
<input type="submit" name="submit" id="submit" value="Registruj se" class="form-control">
</div>
</div>
</form>
</div>
</div>
and here's the insert script (insert.php) :
<?php
global $connection;
global $errordanger, $uspehreg;
$fname = $lname = $email = $password = "";
if(isset($_POST['submit'])){
$ime = $_POST['ime'];
$prezime = $_POST['prezime'];
$email = $_POST['email'];
$passw = $_POST['password'];
//Provera da li korisnik vec postoji
$sql_query = mysqli_query($connection, "SELECT * FROM signup WHERE email = '{$email}' ");
$count = mysqli_num_rows($sql_query);
if($count > 0){
$errordanger = "<div class='alert alert-danger' role='alert'>
Korisnik sa tom email adresom vec postoji!
</div>";
}else{
$fname = mysqli_real_escape_string($connection, $ime);
$lname = mysqli_real_escape_string($connection, $prezime);
$email = mysqli_real_escape_string($connection, $email);
$password = mysqli_real_escape_string($connection, $passw);
$sql = "INSERT INTO signup(email, ime, prezime, password, date_time) VALUES ('{$email}' , '{$ime}', '{$prezime}', '{$passw}', now()) ";
$query = mysqli_query($connection, $sql);
if(!$query){
die(" Neuspesno upisivanje u bazu podataka! " . mysqli_error($connection));
}else{
$uspehreg = "<div class='alert alert-success'>
<strong>Uspesno ste se registrovali!</strong> Indicates a successful or positive action.
</div>";
}
}
}
?>