Jump to content

function to implode array and insert record


lilgezuz

Recommended Posts

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);

}}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.