Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DbConfig
- {
- private $_host = 'localhost';
- private $_username = 'root';
- private $_password = '';
- private $_database = 'machines';
- protected $connection;
- public function __construct()
- {
- if (!isset($this->connection)) {
- $this->connection = new mysqli($this->_host, $this->_username, $this->_password, $this->_database);
- if (!$this->connection) {
- echo 'Cannot connect to database server';
- exit;
- }
- }
- return $this->connection;
- }
- }
- ?>
- $scope.columns = [
- {"id":1,"brand":"robotworx","tonnage":"200","tableSize":"20x50","pressType":"Kiss Cutting"},
- {"id":2,"brand":"fanuc","tonnage":"100","tableSize":"30x60","pressType":"Swing Arm"}
- ];
- $scope.register=function(){
- $http.post("http://localhost/clickermag/controller/register.php", {
- 'company':$scope.company,
- 'email':$scope.email,
- 'phone':$scope.phone,
- 'position':$scope.position,
- 'firstName':$scope.firstName,
- 'lastName':$scope.lastName,
- 'presses':$scope.columns
- })
- .then(function(response){
- console.log("Data Inserted Successfully");
- },function(error){
- alert("Sorry! Data Couldn't be inserted!");
- console.error(error);
- });
- }
- <?php
- $data = json_decode(file_get_contents("php://input"));
- //including the database connection file
- include_once("../classes/Crud.php");
- $crud = new Crud();
- $company = $data->company;
- $email = $data->email;
- $phone = $data->phone;
- $position = $data->position;
- $firstName = $data->firstName;
- $lastName = $data->lastName;
- $ownedPress = $data->presses;
- //insert data to database
- $result = $crud->execute("INSERT INTO users(account_type, company, website, email, phone, password, position, first_name, last_name, country, state, city, offer_contract_cutting, contact_for_contract_cutting) VALUES('$account','$company','$website','$email','$phone','$password','$position','$firstName','$lastName','$country', '$state', '$city', '$offerContractCutting', '$contactForContractCutting')");
- $last_id = $crud->user_id;
- foreach($data as $item) {
- $pressesQuery = $crud->execute("INSERT INTO owned_presses(user_id, brand, tonnage, table_size, press_type) VALUES ('$last_id','$item[brand]','$item[tonnage]','$item[tableSize]','$item[pressType]')");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement