Only writes ID 0

0

I have a problem that I have tried in many ways, but the only one is writing the Zero id.

Part of the button to register the street in the neighborhood

Neighborhood Listings

neighborhood_list.php

Part of the button to register the street in the neighborhood Listing of neighborhoods

<?php
while ($linha = mysql_fetch_array($resultado)) { ?>
<tr>
	<td><?php echo $linha['nome']; ?></td>
	<td class="actions " style="width: 38.66666667%;">
		<button type="button" name="addRua" id="<?php $linha['id']; ?>" data-toggle="modal" data-target="#addRua_data_Modal_rua" class="btn btn-warning btn-xs id_cod_bairro" >Cadastrar Rua</button>
	</td>
	
<?php } ?>  	

Part of the Modal where you set the values to be written

<div id="addRua_data_Modal_rua" class="modal fade" data-backdrop="static">  
  <div class="modal-dialog">  
	   <div class="modal-content">  
			<div class="modal-header">  
				 <!--<button name="fecharRua" id="fecharRua" type="submit" class="close" data-dismiss="modal">&times;</button>  -->
				 <input type="submit" name="fecharRua" id="fecharRua" value="&times;" class="close" data-dismiss="modal" />
				 <!--<h4 class="modal-title" name="insert" id="insert" value="Adicionar" >Adicionar / Atualizar</h4>-->
				 <label type="text" name="insert_title" id="insert_title" value="Cadastrar Bairro" class="modal-title" />	 
			</div>  
			<div class="modal-body">  
				 <form method="post" id="insert_form_rua">  
					   <select name="tiporua" id="tiporua" class="form-control">  
						   <option value="Rua">Rua</option>  
						   <option value="Travessa">Travessa</option>  
						   <option value="Avenida">Avenida</option>
					  </select>  
				  
					  <br /> 
					  <label>Digite o nome da Rua</label>						  
					  <input type="text" name="nome_rua" id="nome_rua" class="form-control" />  					
					  <br />  
					  <input type="hidden" name="employee_id" id="employee_id" /> 
					  <input type="submit" name="insert" id="insert" value="Insert" class="btn btn-success" />
				 </form> 
				 
			</div>  
			<div class="modal-footer">  
				 <input type="submit" name="fecharRua02" id="fecharRua02" value="Sair" class="btn btn-default" data-dismiss="modal" />
			</div>  
	   </div>  
  </div>  
</div>  

Part of javascript where it directs to write

$(document).ready(function(){  
 $('#addRua').click(function(){  
 var id_cod_bairro = $(this).attr("id");
	   $('#insert').val("Cadastrar");  
	   $('#insert_title').val("Cadastrar Rua");
	   

  }); 
  $('#insert_form_rua').on("submit", function(event){  
	   event.preventDefault();  
	   if($('#nome_rua').val() == "")  
	   {  
			alert("nome is required");  
	   }    
	   else  
	   {  
			$.ajax({  
				 url:"insert_bairro_rua.php?id_usuario=<?php echo $_GET["id_usuario"]; ?>&cod_bairro=id_cod_bairro",  
				 method:"POST",  
				 data:{employee_id:employee_id},  
				 data:$('#insert_form_rua').serialize(), 				 
				 beforeSend:function(){  
					  $('#insert').val("Inserindo Dados..."); 
					  $('#insert_form_rua')[0].reset();
					  
					  
				 },  
				 success:function(data){  
					  $('#addRua_data_Modal_rua').modal('hide');  
					  $('#employee_table').html(data);
					  $('#insert_form_rua')[0].reset();						  
				 }  
			}); 
			
	   }  
  });  

insert_bairro_rua.php

Where you write the data in Mysql

 <?php  
 include("/lib/conexao.php");
 if(isset($_POST["employee_id"]))  
 {  
	  $id_usuario = $_GET["id_usuario"]; 
	  $cod_bairro = $_GET["cod_bairro"]; 
	  $nome_rua = filter_input(INPUT_POST, 'nome_rua', FILTER_SANITIZE_SPECIAL_CHARS);
	  $tiporua = filter_input(INPUT_POST, 'tiporua', FILTER_SANITIZE_SPECIAL_CHARS);
	  
	  
      if($_POST["employee_id"] != '')  
      {  
		$query = "  
			   UPDATE rua   
			   SET   
			   nome='$nome_rua',   
			   tiporua='$tiporua',
			   cod_bairro='$cod_bairro',
			   id_usuario='$id_usuario'
			   WHERE id='".$_POST["employee_id"]."'"
			   ;	
		mysql_query($query,$conexao);	
      }  
      else  
      {  
		$query = "  
			   INSERT INTO rua(nome, tiporua, cod_bairro, id_usuario)  
			   VALUES('$nome_rua', '$tiporua','$cod_bairro','$id_usuario');
			   ";	
		mysql_query($query,$conexao);		   
        $message = 'Data Inserted';  		
      }   	  
 }  
 ?>

I only have some notions of these codes.

    
asked by anonymous 03.12.2017 / 17:06

1 answer

0

On your register button in the id is missing the function echo

Wrong:

id="<?php $linha['id']; ?>"

Correct:

id="<?php echo $linha['id']; ?>"
    
04.12.2017 / 02:36