Inserting 2 rows instead of one: angular and php

33
February 11, 2019, at 08:00 AM

I am working with angular 6 and php. When i add an entity whith my application, i find that the backend is inserting 2 rows in the table instead of one.

I tried removing some lines to locate the problem. When i remove this two lines

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

it only adds one row but with empty field. When i put them back, the application add two rows, one of them is empty , the other contains my input. Here is the php file to insert a row

<?php
 header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
$data = json_decode(file_get_contents("php://input"));
$sql = "INSERT INTO employees (name, position, department, salary)
VALUES ('$data->name', '$data->position', '$data->department', '$data->salary')";
if($data->name){
    $qry = $conn->query($sql);
}
$conn->close();
?>
READ ALSO
Merge dataframes by left join SQL &amp; Pandas

Merge dataframes by left join SQL & Pandas

I made two tables into a MySQL database using PythonThe following SQL code is to perform join on two tables in the database

43
Using an auto_increment sequence for cursor purpose in mysql ? Any other Alternative?

Using an auto_increment sequence for cursor purpose in mysql ? Any other Alternative?

I m creating a application where there are users and posts, and user can likes posts, so i have created a table ,

19
MySQL - Using COALESCE with DATE_ADD and DATE_SUB to get next/previous record

MySQL - Using COALESCE with DATE_ADD and DATE_SUB to get next/previous record

I am trying to query MySQL to select the previous and next recordI need help in using COALESCE and DATE_ADD/DATE_SUB together

36