我对此主题有疑问。事情如下,我目前是面向对象的PHP编程的初学者,我在编码时遇到了一个问题。当我开始INSERT INTO'dB name'时它起作用了。但问题是每当我去PHPmyAdmin时,我都会看到空白区域,我的数据应该是。
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL);
class DBinject{
public $naamroute;
public $soortroute;
public $tijdsduur;
public $lengteroute;
public function setroutename($routename){
if(!is_string($routename) || empty($routename)){
return false;
}
$this->naamroute = $routename;
}
public function setroute($route){
if(!is_string($route) || empty($route)){
return false;
}
$this->soortroute = $route;
}
public function settimelength($timelength){
if(!is_string($timelength) || empty($timelength)){
return false;
}
$this->tijdsduur = $timelength;
}
public function setroutelength($routelength){
if(!is_string($routelength) || empty($routelength)){
return false;
}
$this->routelengte = $routelength;
}
public function Opslaan(){
$conn = new mysqli("localhost", "root", "root", "fietsroutes");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo"Connected succesfully.";
}
$query = "INSERT INTO fietsroutes (naamroute, soortroute, tijdsduur, lengteroute)
VALUES('$this->naamroute', '$this->soortroute', '$this->tijdsduur', '$this->lengteroute')";
$result = $conn->query($query);
return $result;
}
}
$conn = new DBinject();
$conn->setnaamroute($_POST['routename']);
$conn->setsoortroute($_POST['route']);
$conn->settijdsduur($_POST['timelength']);
$conn->setlengteroute($_POST['routelength']);
$conn->Opslaan();
?>
凸块
答案 0 :(得分:0)
您实际上从未在您提供的代码中为变量('$this->naamroute', '$this->soortroute', '$this->tijdsduur', '$this->lengteroute')
提供任何值,因此您实际上是将空值放入数据库。
答案 1 :(得分:0)
您的表名和数据库名是否相同?正如你所说的那样,你正在解雇&#34; INSERT INTO&#39; dB名称&#39;&#34;所以请尝试INSERT INTO&#39; table-name&#39;我认为这是问题..