Sunday 12 November 2017

mysql - PHP Column not found in a different query

I've a script in PHP to store data in a database. The
script is called functions.php, this is its
content:



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;
}
}


When
I call regMes function, it stores the data correctly on de database, but when I call
regEventoSecu, regEventoPrim and regEventePreesc functions through a html form I get
this error:




PHP
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not
found: 1054 Unknown column 'dia' in 'field list'' in
/home/noewebst/public_html/act_eventos/functions.php:29

Stack
trace:










thrown in
/home/noewebst/public_html/act_eventos/functions.php on line
29





This
is the form to save data.



            
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();
}
?>






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";
}

}
?>




action="" method="post" name="reg">













placeholder="Descripción">
placeholder="Descripción">
onclick="return(submitreg());">








href="actualizar.php">Regresar




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...