-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenericinsert.php
More file actions
32 lines (26 loc) · 888 Bytes
/
genericinsert.php
File metadata and controls
32 lines (26 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
function GenericInsertData($table, $formdata)
{
$db_host="localhost";
$db_user="root";
$db_pass="password";
$db_name="db";
$con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if(!$con){
die("connection failed : ". mysqli_connect_error());
}
// retrieve the keys of the array (column titles)
$fields = array_keys($formdata);
// build the query
$sql = "INSERT INTO ".$table."
(`".implode('`,`', $fields)."`)
VALUES('".implode("','", $formdata)."')";
// run and return the query result resource
$run_query=mysqli_query($con, $sql) or die(mysqli_error($con));
if($run_query){
echo "success";
}else{
echo "An Error Occured";
}
}
?>