Send value via post php ajax [closed]

1

I have these 3 script where one I collect values by means of ajax from another but I want to send the value collected from the other script generated by ajax.

this is the index

<html>
<head>
 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
 <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script language="javascript">
$(document).ready(function(){
   $("#nombre").change(function () {
           $("#nombre option:selected").each(function () {
            elegido=$(this).val();
            $.post("modelos.php", { elegido: elegido }, function(data){
            $("#telefono").html(data);
            });            
        });
   })
});
</script>



 
</head>
<body>
<form action="combo2.php" method="post">
<p>Marca: 
<select name="nombre" id="nombre">    
<?php
$con = mysql_connect('localhost','root', 'master3.1416');
            mysql_select_db('tel', $con);
        
            $sql = mysql_query("SELECT * FROM tel ORDER BY nombre " ,$con);
              
            $contar = @mysql_num_rows($sql);
              
            if($contar == 0){
           
            }else{
              while($row=mysql_fetch_array($sql)){
                $id = $row['id'];
			
?>
    <option value='<?php echo $nombre = $row["nombre"]; ?>'> <?php echo $nombre = $row["nombre"]; ?>  </option>
   <?php  
	   }
			}
	 ?> 
</select> </p>
<p>Modelo:
<select name="telefono" id="telefono">    
    <option value='<?php echo $tel = $row["tel"]; ?>' name='tel' id='tel'>   </option>
</select></p>
<input name='submit' type='submit' value='Guardar' />
</form>
</body>
</html>

The above script picks up the value from this script below.

<?php
$elegido = $_POST['elegido'];
$con = mysql_connect('localhost','root', 'master3.1416');
            mysql_select_db('tel', $con);
        
            $sql = mysql_query("SELECT * FROM tel  WHERE nombre = '$elegido'" ,$con);
              
            $contar = @mysql_num_rows($sql);
              
            if($contar == 0){
           
            }else{
              while($row=mysql_fetch_array($sql)){
                $tel = $row['tel'];
				
				
				echo '<option value="'.$row['tel'].'" id="tel" name="tel">'.$row['tel'].'</option>';
			}
			  }
			
?>

But the value I want to send here, but only send me the name:

<?php 

$nombre = $_POST['nombre'];
$tel = $_POST['tel'];

echo" $nombre";
echo" $tel";

?>
    
asked by Leonardo 28.09.2017 в 04:07
source

1 answer

0

Replace the lines where you create the select to put the names by this:

<select name="nombre" id="nombre">    
<?php
$con = mysql_connect('localhost','root', 'master3.1416');
            mysql_select_db('tel', $con);

            $sql = mysql_query("SELECT * FROM tel ORDER BY nombre " ,$con);

            $contar = @mysql_num_rows($sql);

            if($contar == 0){

            }else{
              while($row=mysql_fetch_array($sql)){
                $id = $row['id'];
                echo '<option value="'.$row["nombre"].'">'.$row["nombre"].'</option>';  
              }     
            }   
?>
</select>

Use the operator. to concatenate chains and thus you do not have to leave the php notice that at the end of your code you create a php tag just to close the keys of the if and the cycle, do not you think it is more comfortable in this way?

    
answered by 28.09.2017 в 19:21