Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Live Search con PHP y MySQL sin actualizar la página

Estoy tratando de hacer una live search . Tengo una página html con un valor de entrada. La entrada tomará ID de venta. Luego tengo un archivo php que se conecta a una base de datos MySQL. Quiero buscar en la base de datos por ID de venta y actualizar una tabla html basada en lo que se escribe en la entrada. Tengo la mayor parte del código, sin embargo, dice que no se ha encontrado nada.

Primero daré mi HTML:=

 <html> <head> <title></title> <script src="jquery-1.11.1.js"></script> <script> $(document).ready(function () { load_data(); function load_data(query) { $.ajax({ url:"test.php", method:"POST", data:{query:query}, success:function(data) { $('#result').html(data); } }); } $('#saleID').keyup(function() { var search = $(this).val(); if(search != '') { load_data(search); } else { load_data(); } }); }); </script> </head> <body> </body> </html> <h1>Test</h1> <br> <br> <form> <p>Customer ID:</p> <input type="text" id="saleID" name="Sale"> <br> <br> </form> <div id="result"></div> </body> </html>

Entonces aquí está mi archivo test.php

 <?php header("Cache-Control: post-check=1, pre-check=2"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); $choice = $_GET['qu']; $output = ''; $con = mysqli_connect("localhost", "milkiewiczr520", "", "milkiewiczr520") or die("Failed to connect to database"); $sql_command = "SELECT * FROM SALES WHERE CUSTOMERID = " . $choice . ";"; $result = mysqli_query($con, $sql_command); if(mysqli_num_rows($result) > 0) { $output .= ' <div> <table> <tr> <th>Sale ID</th> <th>Sale Date</th> <th>Customer ID</th> </tr> '; while($row = mysqli_fetch_array($result)) { $output .= ' <tr> <td>'.$row["SALEID"].'</td> <td>'.$row["SALEDATE"].'</td> <td>'.$row["CUSTOMERID"].'</td> </tr> '; } echo $output; } else { echo 'Data Not Found'; } ?>

No estoy obteniendo datos encontrados.

¿Algunas ideas?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Obtiene sus datos con $_GET mientras envía datos como POST. Haga de esta manera para obtener su consulta:

 $choice = $_POST['query']; // the {query:query} parameter you declared in your ajax call

(en lugar de: $choice = $_GET['qu']; )

Por cierto, intente usar PDO para hacer solicitudes más seguras.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!