lilgezuz Posted February 1, 2015 Share Posted February 1, 2015 Not sure if this is right. I can't get it to insert my record. Can someone please tell me if I'm doing it right? cus_functions.php function dbRowInsert($table_name, $form_data) { global $conn; $fields = array_keys($form_data); $sql = "INSERT INTO ".$table_name." (`".implode('`,`', $fields)."`) VALUES('".implode("','", $form_data)."')"; return mysqli_query($sql); } process.php include("new_db.php"); include("cus_functions.php"); $do=$_GET['do']; if($do=='addpro'){ if(isset($_POST['submit'])){ $input = $_POST['title']; $comp = '0'; $form_data = array('title' => $input, 'completed' => $comp); dbRowInsert('projects', $form_data); }} Quote Link to comment https://forums.phpfreaks.com/topic/294300-function-to-implode-array-and-insert-record/ Share on other sites More sharing options...
Solution lilgezuz Posted February 1, 2015 Author Solution Share Posted February 1, 2015 Never mind forgot to put return mysqli_query($conn,$sql); Quote Link to comment https://forums.phpfreaks.com/topic/294300-function-to-implode-array-and-insert-record/#findComment-1504492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.