get p content to give value to a php variable [closed]

0

I am creating an administration panel with Modals, I need to get the id to change the records in the database, I have chosen to give value to a paragraph from the click on the edit button, however I can not get the value, I get the following error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
 in C:\wamp\www\

The code is the following ...

$id = ".$('.sliderId').html().val().";
$conn = mysqli_connect('localhost','root','','360');
$sql = "SELECT * FROM imagenes_slider WHERE id = '".$id."'";
$result = mysqli_query($conn,$sql);

The slider to change has the id: <p id='sliderId'>1</p>

Any ideas?

    
asked by Guillermo Armando Alvarez 24.10.2017 в 12:04
source

1 answer

2

As we do not have the complete code, I'll give you an approximation:

  

HTML file (eg index.html):

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <p id='sliderId'>Hola</p> 
        <button id="enviar">Enviar</button>

        <!-- JS CODE -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
        $(document).ready(function(){
            $("#enviar").click(function(){
                $.ajax({
                    method: "POST",
                    url: "script.php",
                    data: { id: $('#sliderId').text() }
                })
                .done(function( msg ) {
                  alert( "Devolución de PHP: " + msg );
                });
            });
        });
        </script>
    </body>
</html>
  

PHP file (eg script.php):

<?php
$id = $_POST['id'];
echo $id;
//Código probado hasta aquí, lo consiguiente es trabajar el PHP
$conn = mysqli_connect('localhost','root','','360');
$sql = "SELECT * FROM imagenes_slider WHERE id = '".$id."'";
$result = mysqli_query($conn,$sql);
?>

Once executed, an alert will appear with the result that PHP returns, in this case we simply make an echo of the received value (content of the div sliderId).

Obviously the code is a sample, and you should adapt it to your needs. Understand that it is a base on which you can work. Finish your PHP with an echo that returns the status of the request to AJAX (it will be what is shown in the alert).

Greetings,

    
answered by 24.10.2017 в 12:53