Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <?php
  2. class DbConfig
  3. {
  4. private $_host = 'localhost';
  5. private $_username = 'root';
  6. private $_password = '';
  7. private $_database = 'machines';
  8.  
  9. protected $connection;
  10.  
  11. public function __construct()
  12. {
  13. if (!isset($this->connection)) {
  14.  
  15. $this->connection = new mysqli($this->_host, $this->_username, $this->_password, $this->_database);
  16.  
  17. if (!$this->connection) {
  18. echo 'Cannot connect to database server';
  19. exit;
  20. }
  21. }
  22.  
  23. return $this->connection;
  24. }
  25. }
  26. ?>
  27.  
  28. $scope.columns = [
  29. {"id":1,"brand":"robotworx","tonnage":"200","tableSize":"20x50","pressType":"Kiss Cutting"},
  30. {"id":2,"brand":"fanuc","tonnage":"100","tableSize":"30x60","pressType":"Swing Arm"}
  31.  
  32. ];
  33.  
  34. $scope.register=function(){
  35. $http.post("http://localhost/clickermag/controller/register.php", {
  36. 'company':$scope.company,
  37. 'email':$scope.email,
  38. 'phone':$scope.phone,
  39. 'position':$scope.position,
  40. 'firstName':$scope.firstName,
  41. 'lastName':$scope.lastName,
  42. 'presses':$scope.columns
  43. })
  44.  
  45. .then(function(response){
  46. console.log("Data Inserted Successfully");
  47. },function(error){
  48. alert("Sorry! Data Couldn't be inserted!");
  49. console.error(error);
  50.  
  51. });
  52. }
  53.  
  54. <?php
  55. $data = json_decode(file_get_contents("php://input"));
  56.  
  57. //including the database connection file
  58. include_once("../classes/Crud.php");
  59.  
  60. $crud = new Crud();
  61.  
  62.  
  63. $company = $data->company;
  64. $email = $data->email;
  65. $phone = $data->phone;
  66. $position = $data->position;
  67. $firstName = $data->firstName;
  68. $lastName = $data->lastName;
  69. $ownedPress = $data->presses;
  70.  
  71. //insert data to database
  72. $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')");
  73.  
  74. $last_id = $crud->user_id;
  75.  
  76. foreach($data as $item) {
  77. $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]')");
  78. }
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement