我在PHP中使用脚本将数据存储在数据库中。该脚本名为functions.php,这是它的内容:
class LoginRegister{
function __construct($db){
$this->db= $db;
}
public function regEventoPreesc($evento1,$desc1,$evento2,$desc2){
$query = $this->db->prepare("INSERT INTO 001_preesc(dia,descripcion) VALUES (?,?),(?,?),(?,?),(?,?)");
$query->execute(array($evento1,$desc1,$evento2,$desc2));
return true;
}
public function regEventoPrim($evento1,$desc1,$evento2,$desc2){
$query = $this->db->prepare("INSERT INTO 002_prim(dia,descripcion) VALUES (?,?),(?,?),(?,?),(?,?)");
$query->execute(array($evento1,$desc1,$evento2,$desc2));
return true;
}
public function regEventoSecu($evento1,$desc1,$evento2,$desc2){
$query = $this->db->prepare("INSERT INTO 003_secu(dia,descripcion) VALUES (?,?),(?,?),(?,?),(?,?)");
$query->execute(array($evento1,$desc1,$evento2,$desc2));
return true;
}
public function regMes($mes){
$query = $this->db->prepare("INSERT INTO mes(mes) VALUES (?)"); //LINE 29
$query->execute(array($mes));
return true;
}
}
当我调用regMes函数时,它会正确地将数据存储在de数据库中,但是当我通过html表单调用regEventoSecu,regEventoPrim和regEventePreesc函数时,我收到此错误:
PHP致命错误:未捕获异常'PDOException',消息'SQLSTATE [42S22]:未找到列:1054 /home/noewebst/public_html/act_eventos/functions.php中'字段列表'中的未知列'dia': 29 堆栈跟踪:
0 /home/noewebst/public_html/act_eventos/functions.php(29):PDOStatement-> execute(Array)
1 /home/noewebst/public_html/act_eventos/act_preesc.php(104):LoginRegister-> regEventoPreesc('示例1','描述1','示例2','描述2')
2 {main}
在第29行的/home/noewebst/public_html/act_eventos/functions.php中引发
这是保存数据的表格。
<?php
session_start();
require_once "functions.php";
$db = new DatabaseConnection();
$user = new LoginRegister($db->pdo);
$uid = $_SESSION['uid'];
$username = $_SESSION['uname'];
if(!$user->getSession()){
header('Location: login.php');
exit();
}
?>
<html>
<head></head>
<body>
<div class="form">
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$evento1=$_POST['evento1'];
$desc1=$_POST['desc1'];
$evento2=$_POST['evento2'];
$desc2=$_POST['desc2'];
$register = $user->regEventoPreesc($evento1,$desc1,$evento2,$desc2);
if($register){
echo "Data succesfully saved";
}
}
?>
<form action="" method="post" name="reg">
<table>
<tr><td><input type="text" name="evento1" placeholder="Día y mes"></td>
<td><input type="text" name="desc1" placeholder="Descripción"></td>
</tr>
<tr><td><input type="text" name="evento2" placeholder="Día y mes"></td>
<td><input type="text" name="desc2" placeholder="Descripción"></td>
</tr>
<tr><td> <input type="submit" name="submit" value="Guardar" onclick="return(submitreg());"></td></tr>
</table>
</form>
</div>
<br><br><br>
<a class="boton_personalizado" href="actualizar.php">Regresar</a><br><br><br>
</body>