Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Invalid argument supplied for foreach() in sqlinfo.php on line 28
- if($row = $result->fetch_assoc() && $result->num_rows === 1){
- foreach($row as $key => $value){ //error
- $(document).ready(function () {
- $(".grid").on("click", ".edit", function (){
- var albumId = $(this).siblings(".grid-info").attr("id");
- var imageId = $(this).siblings("img").attr("id");
- var request = (albumId == '') ? {requestType: 'Album', id: albumId} : {requestType: 'Image', id: imageId};
- var getSQLInfo = $.ajax({
- url: '../P3_M2/ajax/sqlinfo.php',
- method: 'post',
- data: request,
- dataType: 'json',
- error: function(error) {
- console.log(error);
- }
- });
- });
- <?php
- require_once('../configsql.php');
- $queryFor = array(
- 'Album' => 'SELECT * FROM Album WHERE id = ?',
- 'Image' => 'SELECT * FROM Image WHERE id = ?');
- $requestType = filter_input(INPUT_POST, 'requestType', FILTER_SANITIZE_STRING);
- if (empty($requestType)) {
- echo 'Missing requestType.';
- die();
- }
- $id = $mysqli->real_escape_string($_POST["id"]);
- $info= array();
- $stmt = $mysqli->prepare($queryFor[$requestType]);
- $stmt->bind_param('i', $id);
- $executed = $stmt->execute();
- if(!$executed){
- echo "SQL query $querFor[$requestType] not executed";
- exit();
- }
- $result = $stmt->get_result();
- $stmt->close();
- if($row = $result->fetch_assoc() && $result->num_rows === 1){
- foreach($row as $key => $value){ //error here
- //Transform SQL field names to form input names for html
- $key = str_replace('_', '-', $key);
- if($key === 'title'){
- $key = strtolower($requestType).'-'.$key;
- }
- $info[$key] = $value;
- }
- }
- // Send back the array as json
- echo json_encode($info);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement