Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dbCon = mysqli_connect("localhost","root","","emailz");
- function submitToDb($table,$array){
- global $dbCon;
- /*
- format:
- for every key value pair, the key is a column and its value is the data to be inserted under said column.
- eg. [animal_type: cat, age: 6] would be INSERT INTO animals (animal_type,age) VALUES ('cat','6');
- */
- $query = "INSERT INTO $table (";
- $count = 0;
- foreach(array_keys($array) as $column){
- $count++;
- $query .= $column;
- if($count < count(array_keys($array))){
- $query .= ",";
- }
- }
- $query .= ")";
- $query .= " VALUES(";
- $count = 0;
- foreach($array as $value){
- $count++;
- $query .= "'".mysqli_real_escape_string($dbCon,$value)."'";
- if($count < count($array)){
- $query .= ",";
- }
- }
- $query .= ");";
- var_dump($query);
- $submission = mysqli_query($dbCon, $query) or die(mysqli_error($submission));
- return ($submission) ? true : false;
- }
- submitToDb("email_subscriptions",[
- 'fullname' => 'fullname',
- 'company' => 'company',
- 'phone' => 'phone',
- 'email' => 'email',
- 'role' => 'role',
- 'inquiry' => 'inquiry'
- ]);
- /*
- CREATE TABLE `email_subscriptions` (
- `es_id` int NOT NULL AUTO_INCREMENT,
- PRIMARY KEY(es_id),
- `fullname` varchar(100) DEFAULT NULL,
- `company` varchar(100) DEFAULT NULL,
- `phone` varchar(100) DEFAULT NULL,
- `email` varchar(100) DEFAULT NULL,
- `role` varchar(20) DEFAULT NULL,
- `inquiry` varchar(2000) DEFAULT NULL,
- `es_id` int(11) NOT NULL
- )
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement