Hello I have a detail is that I have a page that shows me the data of a bd table then when I'm going to modify it opens a modal and loads me the data, until there all the problem comes when I update it I get the error:
Fatal error: Uncaught Error: Call to undefined method Database :: update () in Path: edita.php: 24
Here I leave my conector.php
<?php
class Database
{
// private static $dbName = 'naw' ;
private static $dbName = 'naw';
// private static $dbHost = 'localhost' ;
private static $dbHost = 'localhost' ;
// private static $dbUsername = 'root';
private static $dbUsername = 'root';
// private static $dbUserPassword = '';
private static $dbUserPassword = '';
private static $cont = null;
public static function connect()
{
// One connection through whole application
if ( null == self::$cont )
{
try
{
self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
}
catch(PDOException $e)
{
die($e->getMessage());
}
}
return self::$cont;
}
public static function query($query) {
try {
$q = self::$cont->prepare($query);
$q->execute();
$data = $q->fetchAll();
} catch (PDOException $e) {
echo $e;
}
return $data;
}
public static function disconnect()
{
self::$cont = null;
}
}
?>
And here my edita.php :
<?php
require_once '../php/conector.php';
$id = $_POST['id'];
$nombre = $_POST['nombre'];
$telefono = $_POST['telefono'];
$correo = $_POST['correo'];
$comuna = $_POST['comuna'];
$actualizado = $_POST['actualizado'];
// function update_modal() {
try {
$pdo = new Database;
$pdo->connect();
$sql = "UPDATE 'menmbresia'
SET 'nombre_apellido' = $nombre ,
'telefono' = $telefono ,
'correo' = $correo ,
'comuna' = $comuna ,
'actualizado' = $actualizado,
WHERE id ='{$id}'";
try {
$w = $pdo->update($sql);
} catch (PDOExecption $e) {
$pdo->rollback();
}
} catch ( PDOExecption $e) {
}
// database::disconnect();
$pdo->disconnect();
return;
// }
?>
I thought about adding this to miconector but I do not know if it's okay
public static function update($sql) {
try {
$q = self::$cont->prepare($sql);
$q->execute();
} catch (PDOException $e) {
echo $e;
}
}
But with that, I do not get an error, but I still do not edit anything, who knows what I could do? with some example or something that I am new in php and less with ajax and php pdo .-.