0
I have a Function that returns me the values of a Grid in a Modal I call the function it makes a Select in PHP and returns me the data within a Modal. Except that besides bringing this data I need to bring names of images that are in another table only that I’m not getting.
JS
function GetUserDetails(id) {
// Add User ID to the hidden field for furture usage
$("#hidden_user_id").val(id);
$.post("ajax/readUserDetails.php", {
id: id
},
function (data, status) {
// PARSE json data
var user = JSON.parse(data);
// Assing existing values to the modal popup fields
$("#show_id").val(id);
$("#show_emailcontato").val(user.EmailContato);
$("#show_titulo").val(user.titulo);
$("#show_tipo_material").val(user.tipo_material);
$("#show_acabamento").val(user.acabamento);
$("#show_quantidade").val(user.quantidade);
}
);
// Open modal popup
$("#show_user_modal").modal("show");
}
readUserDetails.php
// include Database connection file
include("db_connection.php");
// check request
if(isset($_POST['id']) && isset($_POST['id']) != "")
{
// get User ID
$user_id = $_POST['id'];
// Get User Details
$query = "SELECT * FROM TblPedidos ped LEFT JOIN TblCadastros cli ON ped.TipoCadastro = cli.TipoCadastro AND ped.idcliente = cli.id WHERE ped.id = '$user_id'";
if (!$result = mysqli_query($con, $query)) {
exit(mysqli_error($con));
}
$response = array();
if(mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$response = $row;
}
}
else
{
$response['status'] = 200;
$response['message'] = "Data not found!";
}
// display JSON data
echo json_encode($response);
}
else
{
$response['status'] = 200;
$response['message'] = "Invalid Request!";
}
I need to insert this query into readUserDetails.php
$query = "SELECT * FROM `tblpedidos_upload` WHERE idpedido = '$userid' ";
if (!$result = mysqli_query($con, $query)) {
exit(mysqli_error($con));
}
sql Injection, use prepare...
– Ivan Ferrer