php - Function not working -
this question has answer here:
the following function not working , cannot see why.
function nuevocontacto($_post) { try { include('func/usarbases.php'); $mensaje="insert `t_contactos`(`id_c`, `nombre`, `telefono`, `telefono2`, `corto`, `celular1`, `celular2`, `email`, `puesto`, `id_a`) values (null,'$_post[nombre]','$_post[tel1]','$_post[tel2]','$_post[corto]','$_post[cel1]','$_post[cel2]','$_post[email]','$_post[puesto]','$_post[id_a]')"; $hacerconsulta = $base->prepare($mensaje); $hacerconsulta->execute(); } catch( pdoexception $e) { echo "<p>error connection: " .$e->getmessage()."</p>"; } $hacerconsulta=null; }
once called code breaks , nothing further executed. when use inside main code works
sorry reedited source , still not working, in include usarbases.php conector pdo called $base
you're lacking database connection in function. add following beginning of function:
global $base;
when add global $base
function you'll able use within function without having re-write whole thing.
unrelated note, worth mentioning.
you open sql injections , you're not using prepared statements should. should using placeholders , binding them later instead of passing directly query.
and tip next time:
state in question what isn't working. expectation , happens.
Comments
Post a Comment