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

190
Views
Making a html alert using ajax, sql and php

I am trying to make some code where a click of a SQL html button can display a different SQL table as a popup. I have already gotten the variable from the table to pass through using this:

echo "<td><a class='btn-floating btn-large waves-effect waves-light black' onclick='partSearch(".$product.")' value='display'><i class='material-icons'>search</i></a></td>";

The 'part search' code is as follows:

    <script type="text/javascript"> 
        function partSearch() {
            $.ajax({
            url: 'serv.php?id=<?php echo $product ?>',
            type: 'GET',
            success: function(result){
                var obj = jQuery.parseJSON(result)
                alert(obj)
            }
            })
        }
    </script> 

Even though the variable is passed through to 'serv.php', I can't manage to get the sql data to be returned as a popup using alert. All I get is either nothing or [object, Object]. This is the SQL/php code:

<?php   
    include 'includes/dbh.inc.php';
    $id = $_GET['id'];
    $result = mysqli_query($conn,"SELECT * FROM pr WHERE product_ID='".$id."'");// test this

    $rows = array();
    while($r = mysqli_fetch_assoc($result)){
        $rows[] = $r;
    }


    echo json_encode($rows);
    ?>  

Any help is appriciated

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

    <script type="text/javascript"> 
            function partSearch() {
                var product_id = "<?php echo $product; ?>";
                $.ajax({
                    url: 'serv.php?id=product_id',
                    type: 'GET',
                    success: function(result){
                      alert(result);
                    }
                })
            }
   </script> 
about 4 years ago · Juan Pablo Isaza 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!