Hello to all the developers. I have a query ... EHH, I'm doing a practice of a CRUD .. and I have the functionality to add and remove completed .. now I need to place the user's data in a specific modal .. I'm trying to place the return of query in a json_encode and pass said array by parameter in a function to be received in JS. but when invoking that function it gives me an error of Uncaught SyntaxError: Unexpected end of input. Could someone help me with this error please ..
you can see that the data is being passed by parameter in the function. but when doing lick .. give that error. This is the code where the data in the database is loaded:
require_once('muestra.php');
try {
$db = new Repository();
$select = $db->Query('SELECT * FROM laptop ORDER BY id ASC');
foreach ($select as $key) {
$datos = json_encode($key);
echo '<tr>';
echo '<td>'.'<center>'.$key['id'].'</center>';
echo '<td>'.$key['marca'].'</center>';
echo '<td>'.'<center>'.$key['pulgadas'].'</center>';
echo '<td>'.$key['especificaciones'].'</center>';
echo '<td>'.$key['precio'].'</center>';
echo '<td><center><i style="cursor:pointer;" class="fa fa-trash" onclick="delet('.$key['id'].');"></i>'.' '.' '.' '.' '.'<i style="cursor:pointer;" class="fa fa-refresh" onclick="addform('.$datos.');" data-toggle="modal" data-target="#myModal"></i></center></td>';
echo '<tr/>';
}
} catch (PDOException $e) {
echo "Se ha producido un error al intentar mostrar los datos". $e->getMessage();
}
Here the file shows.php:
class Repository
{
function getConnection()
{
$username = 'root';
$password = '1RizpPfTeBsqEbku';
$dsn = 'mysql:dbname=tecno;host=127.0.0.1';
try {
$connection = new PDO($dsn,$username,$password);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $connection;
}
catch (PDOException $e) {
echo "Se he producido un Error al intentar conectar al Servidor MySql: ". $e->getMessage();
}
function Query($sql)
{
try {
$connection = $this->getConnection();
$query = $connection->prepare($sql);
$query->execute();
return $query;
} catch (PDOException $e) {
echo "Se ha producido un error en la Consulta". $e->getMessage();
}
}
}