Jump to content
  • Advertisement
Sign in to follow this  
Pedro Alves

select value with angular problem

This topic is 447 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i can´t insert a value of my select option in my querry

this is my code what i doing wrong

this is my code

<div ng-app="sa_app" ng-controller="controller" ng-init="show_data()">
		<div id="myModal" class="modal fade" role="dialog" align="center">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      <div class="modal-body">
      	<label>Nome do Servico</label>
            <input type="text" name="nome" ng-model="nome" class="form-control">
            <input type="text" name="descricao" ng-model="descricao" class="form-control">

            <input type="text" name="quantidade" ng-model="quantidade" class="form-control">
			<label>Nome da Empresa</label>
			<div ng-app="sa_app" ng-controller="controller" ng-init="show_data1()">
			<select  name="Nome" ng-model="Nome" class="form-control">
   <option ng-repeat="x in name" value="{{x.Nome}}">{{x.Nome}}</option>
            <!--input type="text" name="Nome" ng-model="Nome" class="form-control"-->
			<label>Preço Sem iva</label>
            <input type="text" name="precosiva" ng-model="precosiva" class="form-control">
            <input type="text" name="descontos" ng-model="descontos" class="form-control">
            <input type="text" name="iva" ng-model="iva" class="form-control">
            <input type="hidden" ng-model="id">
            <!--input type="submit" name="insert" class="btn btn-primary" ng-click="insert()" value="{{btnName}}"-->
      <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Sair</button>
        <button type="button" class="btn btn-primary" name="insert" ng-click="insert()" value="{{btnName}}" data-dismiss="modal">Insert</button>


var app = angular.module("sa_app", []);
app.controller("controller", function($scope, $http) {
    $scope.btnName = "Insert";
    $scope.insert = function() {
        if ($scope.nome == null) {
            alert("Insira o nome do Servico");
        } else if ($scope.descricao == null) {
            alert("Insira a descricao");
        } else if ($scope.quantidade == null) {
            alert("insira a quantidade");
			/*} else if ($scope.Nome == null) {
            alert("insira a Nome da Empresa");
			} else if ($scope.precosiva == null) {
            alert("insira a O Valor do Preço");
			} else if ($scope.descontos == null) {
            alert("insira a O Valor do Desconto");
			} else if ($scope.iva == null) {
            alert("insira a O Valor do IVA");
        } else {
                "servicos/insert.php", {
                    'nome': $scope.nome,
                    'descricao': $scope.descricao,
                    'quantidade': $scope.quantidade,
					 'Nome': $scope.Nome,
					  'precosiva': $scope.precosiva,
					   'descontos': $scope.descontos,
					    'iva': $scope.iva,
                    'btnName': $scope.btnName,
                    'id': $scope.id
            ).success(function(data) {
                $scope.nome = null;
                $scope.descricao = null;
                $scope.quantidade = null;
				 $scope.precosiva = null;
				 $scope.descontos = null;
				 $scope.iva = null;
                $scope.btnName = "Insert";
    $scope.show_data = function() {
            .success(function(data) {
                $scope.names = data;
	$scope.show_data1 = function() {
            .success(function(data) {
                $scope.name = data;
    $scope.update_data = function(id,nome,descricao,quantidade,Nome,precoiva,descontos,iva) {
        $scope.id = id;
       $scope.nome = nome;
                $scope.descricao =descricao;
                $scope.quantidade = quantidade;
				 $scope.precosiva = precoiva;
				 $scope.descontos= descontos;
				 $scope.iva = iva;
        $scope.btnName = "Update";
     $scope.delete_data = function(id) {
        if (confirm("Are you sure you want to delete?")) {
            $http.post("servicos/delete.php", {
                    'id': id
                .success(function(data) {
                   // alert(data);
        } else {
            return false;
require_once ('../../configurations/config.php');
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
$info = json_decode(file_get_contents("php://input"));
if (count($info) > 0) {
    $nome     = mysqli_real_escape_string($conn, $info->nome);
    $descricao    = mysqli_real_escape_string($conn, $info->descricao);
    $quantidade      = mysqli_real_escape_string($conn, $info->quantidade);
	 $nomeempr    = mysqli_real_escape_string($conn, $info->Nome);
    $precoiva      = mysqli_real_escape_string($conn, $info->precosiva);
	 $descontos    = mysqli_real_escape_string($conn, $info->descontos);
    $iva      = mysqli_real_escape_string($conn, $info->iva);
    $btn_name = $info->btnName;
    if ($btn_name == "Insert") {
        $query = "INSERT INTO servicos(nome, descricao, quantidade, id_empresa, precosiva, descontos, iva) VALUES ('$nome', '$descricao', '$quantidade',(SELECT id from empresa where Nome='$nomeempr'), '$precoiva', '$des','$iva')";
        if (mysqli_query($conn, $query)) {
            echo "Data Inserted Successfully...";
        } else {
            echo 'Failed';
    if ($btn_name == 'Update') {
        $id    = $info->id;
        $query = "UPDATE servicos SET name = '$nome', descricao = '$descricao', quantidade = '$quantidade', quantidade = '$quantidade',id_empresae = '$nomeempr',precosiva = '$precoiva',descontos = '$des',iva = '$iva' WHERE id = '$id'";
        if (mysqli_query($conn, $query)) {
            echo 'Data Updated Successfully...';
        } else {
            echo 'Failed';


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!