Insert custom mysql with viewer_functions
3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 17, 2023 (RSS)
By AlanAlonso - March 16, 2023
Is there a shortcut using viewer_functions to insert custom mysql to the cmsb database, to avoid using this?
$conexion = mysqli_connect("localhost","user","pass","database");
if(!$conexion){
die('No se puede conectar '.mysql_error());
}
if (mysqli_query($conexion, $output )) {
header("Location: alumnos.php");
die();
} else {
echo mysqli_error($conexion);
}
mysqli_close ($conexion);
By Dave - March 17, 2023
Hi Alan,
We have a few internal functions you can use. Here are some options:
$colsToValues = [
'title' => 'test title',
'content' => 'test content',
];
$newRecordNum = mysql_insert($tableName, $colsToValues);
Or you can get the mySQL object directly with mysqli() like this:
$result = mysqli()->query($query);
if (!$result) { dieAsCaller("MySQL Error: ". htmlencode(mysqli()->error) . "\n"); }
Hope that helps! Let me know any questions.
interactivetools.com
By AlanAlonso - March 17, 2023
Thank you Dave
The mysqli object working like a charm y will check mysql_escape() function.
ob_start();
include 'calificaciones_save_post.php';
$output = ob_get_clean();
if (mysqli()->query($output)) {
header("Location: alumnos.php");
die();
} else {
dieAsCaller("MySQL Error: ". htmlencode(mysqli()->error) . "\n");
}