samedi 11 juin 2016

PHP query returning junk data with mysql and mysqli [duplicate]


This question already has an answer here:

EDIT: Updated to misqli and still get the same. I have included the connect.php file as well.

I tried to find the source, but with no luck. Here are my files:

table.php

<!DOCTYPE html>
<html>
<head>
    <title>Vizualizare curse care sosesc!</title>
</head>
<body>
<h1>Curse care vor sosi:</h1>
    <tr>
       <td> <input type="button" id="display" value="Display All Data" /> </td>
    </tr>
    <ul id="lista">

    </ul>

<script src="jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#display").click(function() {
            var lista = $('#lista');
            $.ajax({
                type: "GET",
                url: "get_sosiri.php",             
                dataType: "json",               
                success: function(data){                    
                    data = JSON.parse(data);
                    $.each(data, function(index, value) {
                    lista.append('<li>' + value['localitate_plecare'] + ' ' + value['localitate_sosire'] + ' - ' + value['ora_plecare']+':'+value['minut_plecare']+' ' + value['ora_sosire'] + ':' + value['minut_sosire']  +'</li>')
                });
            });
        });
    });
});
</script>
</body>
</html>

get_sosiri.php

<?php
header('Content-Type: application/json');
include "connect.php";
$ora = date('G');
$query = "SELECT * FROM `autogara`";
$sosiri = array();
$result = mysqli_query($query);
while($row = mysqli_fetch_assoc($result)){
    $sosiri[] = $row;
}
echo json_encode($sosiri);
?>

connect.php

<?php
session_start();
$host = "localhost"; //acc bd 
$utilizator = "root";
$parola = "";
$numebd = "salidb";

//Conectare baza de date
$conn = mysqli_connect("$host", "$utilizator", "$parola");
if (!$conn) {
  echo 'Conectare nereusita la MySQL';
  exit;
}
//Selectare baza de date
if (!mysqli_select_db($conn, $numebd)) {
  echo 'Baza de date nu a putut fi selectata deoarece : '. mysql_error();
  exit;
}


$sql = "SET NAMES 'utf8'";
mysqli_query($conn, $sql);

?>

I'm trying to display some data, but for some reason get_sosiri.php is returning junk data as seen below:

<br />
<font size='1'><table class='xdebug-error xe-deprecated' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:UsersCamilDesktopProjTrainsconnect.php on line <i>9</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>237800</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:UsersCamilDesktopProjTrainsget_sosiri.php' bgcolor='#eeeeec'>...get_sosiri.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0009</td><td bgcolor='#eeeeec' align='right'>242528</td><td bgcolor='#eeeeec'>include( <font color='#00bb00'>'C:UsersCamilDesktopProjTrainsconnect.php'</font> )</td><td title='C:UsersCamilDesktopProjTrainsget_sosiri.php' bgcolor='#eeeeec'>...get_sosiri.php<b>:</b>3</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0012</td><td bgcolor='#eeeeec' align='right'>244328</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mysql-connect' target='_new'>mysql_connect</a>
(  )</td><td title='C:UsersCamilDesktopProjTrainsconnect.php' bgcolor='#eeeeec'>...connect.php<b>:</b>9</td>

The connect.php is working properly, as I have been able to add data to the DB, but if need be, I'll ad it as well.

Any help/tips would be greatly appreciated!


Aucun commentaire:

Enregistrer un commentaire