首先,我用Google搜索了4个多小时。甚至在stackoverflow上发现了十几个类似的问题,但我真的找不到解决方案。所以这就是为什么我写了一个新问题..我几乎是一个新手,我真的尝试了我自己的一切,我在这里找到的答案,但似乎没有任何工作。 顺便说一句,抱歉我的英语不好..
所以当我尝试将新的用户注册输入提交到数据库时,这是我的错误:
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!
这里是数据库连接代码(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));
}
?>
这是注册表(reg.php)文件:
<?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>
这里是插入脚本(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>";
}
}
}
?>
答案 0 :(得分:1)
insert.php
中的代码:
global $connection;
$sql_query = mysqli_query($connection, "SELECT * FROM signup WHERE email = '{$email}' ");
鉴于您没有启动任何范围(函数,类或命名空间),global
关键字毫无意义,但无论如何。
您未包含设置$connection
变量的文件。
reg.php
中包含insert.php
的,后一个文件依赖于$connection
变量,但是在konekcija.php
中设置但您没有包含该文件,因此{{ 1}}没有价值。
答案 1 :(得分:-2)
那我的家伙怎么样?我没有将我的数据库连接文件包含在insert.php脚本中。从我加入它就像魅力一样!
@Alex注意到了,所以再次感谢你哥们!我无法表达我现在的感激和快乐!答案 2 :(得分:-3)
尝试在
中更改insert.php中的SQL QUERY$sql_query=mysqli_query($connection, "SELECT * FROM signup WHERE email = '$email' ") ;