When I'm trying to retrieve a value from php file to javascript












1














I am trying to get a value from php file ,php file retrieve data from ORACLE DATABASE, to a script js this is the php file :



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = oci_parse($con, "SELECT s.song_path, s.song_id, s.TITLE, r.Artist_Name, a.artworkpath FROM songs s, artists r, albums a WHERE s.artist_id = r.artist_id AND a.album_id = s.album_id AND song_id='$songId'");
oci_execute($query);
$resultArray = oci_fetch_array($query);

echo json_encode($resultArray,JSON_FORCE_OBJECT);
}
?>


it works and successfully retrieve data from the tables.



The script that uses data:



<?php
$songQuery = oci_parse($con, "SELECT song_id from songs order by dbms_random.value");
oci_execute($songQuery);
$resultArray = array();

while(($row = oci_fetch_array($songQuery, OCI_BOTH)) != false) {
array_push($resultArray, $row['SONG_ID']);
}

$jsonArray = json_encode($resultArray, JSON_FORCE_OBJECT);
?>

<script>

$(document).ready(function() {
currentPlaylist = <?php echo $jsonArray; ?>;
audioElement = new Audio();
setTrack(currentPlaylist[0], currentPlaylist, false);
});


function setTrack(trackId, newPlaylist, play) {

$.post("includes/handlers/ajax/getSongJson.php", { songId: trackId }, function(data) {

var track = JSON.parse(data);
$(".trackName span").text(track.TITLE);
$(".artistName span").text(track.ARTIST_NAME);
$(".albumLink img").attr("src", track.ARTWORKPATH);

audioElement.setTrack(track.SONG_PATH);
audioElement.audio.play();
});

if(play == true) {
audioElement.audio.play();
}
}

function playSong() {
if(audioElement.audio.currentTime == 0) {
$.post("includes/handlers/ajax/updatePlays.php", { songId: audioElement.audio.currentlyPlaying.SONG_ID});
}

$(".controlButton.play").hide();
$(".controlButton.pause").show();
audioElement.audio.play();}


function pauseSong() {
$(".controlButton.play").show();
$(".controlButton.pause").hide();
audioElement.audio.pause();
}

</script>


All the functions work well except



(songId: audioElement.audio.currentlyPlaying.SONG_ID) 


It don't recognize SONG_ID which is a column from database retrieved in the php file (ajax/getSongJson.php)



PS: the (ajax/updatePlays.php) file is a php file that is for Updating DATA (PLAYS) when the user use playSong function when the current time = 0 so it increment the PLAY colomn in the database by 1



The update php file



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = OCI_parse($con, "UPDATE songs SET plays = plays + 1 WHERE song_id='$songId'");
oci_execute($query);
}
?>


This is the script file when I created a Audio Class, used in the script:



var currentPlaylist = ;
var audioElement;


function Audio() {

this.currentlyPlaying;
this.audio = document.createElement('audio');

this.setTrack = function(track) {
this.currentlyPlaying = track;
this.audio.src = track.SONG_PATH;
}

this.play = function() {
this.play();
}

this.pause = function() {
this.pause();
}

}


The error says :




Uncaught TypeError: Cannot read property 'SONG_ID' of undefined

at playSong ((index):140)

at HTMLButtonElement.onclick











share|improve this question




















  • 3




    You need to post the relevant code here.
    – jeroen
    Nov 23 '18 at 12:02






  • 2




    And not as a picture, pelase
    – Mawg
    Nov 23 '18 at 12:04






  • 1




    Please go read How to Ask, Minimal, Complete, and Verifiable example, and meta.stackoverflow.com/questions/251361/… The code relevant to your problem belongs directly into your question, in text form. Please edit accordingly. (And keep the relevant part in mind.)
    – misorude
    Nov 23 '18 at 12:12










  • I have edited it thank you!
    – oussama eddahri
    Nov 23 '18 at 12:24










  • Please anyone have answer??
    – oussama eddahri
    Nov 23 '18 at 14:02
















1














I am trying to get a value from php file ,php file retrieve data from ORACLE DATABASE, to a script js this is the php file :



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = oci_parse($con, "SELECT s.song_path, s.song_id, s.TITLE, r.Artist_Name, a.artworkpath FROM songs s, artists r, albums a WHERE s.artist_id = r.artist_id AND a.album_id = s.album_id AND song_id='$songId'");
oci_execute($query);
$resultArray = oci_fetch_array($query);

echo json_encode($resultArray,JSON_FORCE_OBJECT);
}
?>


it works and successfully retrieve data from the tables.



The script that uses data:



<?php
$songQuery = oci_parse($con, "SELECT song_id from songs order by dbms_random.value");
oci_execute($songQuery);
$resultArray = array();

while(($row = oci_fetch_array($songQuery, OCI_BOTH)) != false) {
array_push($resultArray, $row['SONG_ID']);
}

$jsonArray = json_encode($resultArray, JSON_FORCE_OBJECT);
?>

<script>

$(document).ready(function() {
currentPlaylist = <?php echo $jsonArray; ?>;
audioElement = new Audio();
setTrack(currentPlaylist[0], currentPlaylist, false);
});


function setTrack(trackId, newPlaylist, play) {

$.post("includes/handlers/ajax/getSongJson.php", { songId: trackId }, function(data) {

var track = JSON.parse(data);
$(".trackName span").text(track.TITLE);
$(".artistName span").text(track.ARTIST_NAME);
$(".albumLink img").attr("src", track.ARTWORKPATH);

audioElement.setTrack(track.SONG_PATH);
audioElement.audio.play();
});

if(play == true) {
audioElement.audio.play();
}
}

function playSong() {
if(audioElement.audio.currentTime == 0) {
$.post("includes/handlers/ajax/updatePlays.php", { songId: audioElement.audio.currentlyPlaying.SONG_ID});
}

$(".controlButton.play").hide();
$(".controlButton.pause").show();
audioElement.audio.play();}


function pauseSong() {
$(".controlButton.play").show();
$(".controlButton.pause").hide();
audioElement.audio.pause();
}

</script>


All the functions work well except



(songId: audioElement.audio.currentlyPlaying.SONG_ID) 


It don't recognize SONG_ID which is a column from database retrieved in the php file (ajax/getSongJson.php)



PS: the (ajax/updatePlays.php) file is a php file that is for Updating DATA (PLAYS) when the user use playSong function when the current time = 0 so it increment the PLAY colomn in the database by 1



The update php file



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = OCI_parse($con, "UPDATE songs SET plays = plays + 1 WHERE song_id='$songId'");
oci_execute($query);
}
?>


This is the script file when I created a Audio Class, used in the script:



var currentPlaylist = ;
var audioElement;


function Audio() {

this.currentlyPlaying;
this.audio = document.createElement('audio');

this.setTrack = function(track) {
this.currentlyPlaying = track;
this.audio.src = track.SONG_PATH;
}

this.play = function() {
this.play();
}

this.pause = function() {
this.pause();
}

}


The error says :




Uncaught TypeError: Cannot read property 'SONG_ID' of undefined

at playSong ((index):140)

at HTMLButtonElement.onclick











share|improve this question




















  • 3




    You need to post the relevant code here.
    – jeroen
    Nov 23 '18 at 12:02






  • 2




    And not as a picture, pelase
    – Mawg
    Nov 23 '18 at 12:04






  • 1




    Please go read How to Ask, Minimal, Complete, and Verifiable example, and meta.stackoverflow.com/questions/251361/… The code relevant to your problem belongs directly into your question, in text form. Please edit accordingly. (And keep the relevant part in mind.)
    – misorude
    Nov 23 '18 at 12:12










  • I have edited it thank you!
    – oussama eddahri
    Nov 23 '18 at 12:24










  • Please anyone have answer??
    – oussama eddahri
    Nov 23 '18 at 14:02














1












1








1


1





I am trying to get a value from php file ,php file retrieve data from ORACLE DATABASE, to a script js this is the php file :



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = oci_parse($con, "SELECT s.song_path, s.song_id, s.TITLE, r.Artist_Name, a.artworkpath FROM songs s, artists r, albums a WHERE s.artist_id = r.artist_id AND a.album_id = s.album_id AND song_id='$songId'");
oci_execute($query);
$resultArray = oci_fetch_array($query);

echo json_encode($resultArray,JSON_FORCE_OBJECT);
}
?>


it works and successfully retrieve data from the tables.



The script that uses data:



<?php
$songQuery = oci_parse($con, "SELECT song_id from songs order by dbms_random.value");
oci_execute($songQuery);
$resultArray = array();

while(($row = oci_fetch_array($songQuery, OCI_BOTH)) != false) {
array_push($resultArray, $row['SONG_ID']);
}

$jsonArray = json_encode($resultArray, JSON_FORCE_OBJECT);
?>

<script>

$(document).ready(function() {
currentPlaylist = <?php echo $jsonArray; ?>;
audioElement = new Audio();
setTrack(currentPlaylist[0], currentPlaylist, false);
});


function setTrack(trackId, newPlaylist, play) {

$.post("includes/handlers/ajax/getSongJson.php", { songId: trackId }, function(data) {

var track = JSON.parse(data);
$(".trackName span").text(track.TITLE);
$(".artistName span").text(track.ARTIST_NAME);
$(".albumLink img").attr("src", track.ARTWORKPATH);

audioElement.setTrack(track.SONG_PATH);
audioElement.audio.play();
});

if(play == true) {
audioElement.audio.play();
}
}

function playSong() {
if(audioElement.audio.currentTime == 0) {
$.post("includes/handlers/ajax/updatePlays.php", { songId: audioElement.audio.currentlyPlaying.SONG_ID});
}

$(".controlButton.play").hide();
$(".controlButton.pause").show();
audioElement.audio.play();}


function pauseSong() {
$(".controlButton.play").show();
$(".controlButton.pause").hide();
audioElement.audio.pause();
}

</script>


All the functions work well except



(songId: audioElement.audio.currentlyPlaying.SONG_ID) 


It don't recognize SONG_ID which is a column from database retrieved in the php file (ajax/getSongJson.php)



PS: the (ajax/updatePlays.php) file is a php file that is for Updating DATA (PLAYS) when the user use playSong function when the current time = 0 so it increment the PLAY colomn in the database by 1



The update php file



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = OCI_parse($con, "UPDATE songs SET plays = plays + 1 WHERE song_id='$songId'");
oci_execute($query);
}
?>


This is the script file when I created a Audio Class, used in the script:



var currentPlaylist = ;
var audioElement;


function Audio() {

this.currentlyPlaying;
this.audio = document.createElement('audio');

this.setTrack = function(track) {
this.currentlyPlaying = track;
this.audio.src = track.SONG_PATH;
}

this.play = function() {
this.play();
}

this.pause = function() {
this.pause();
}

}


The error says :




Uncaught TypeError: Cannot read property 'SONG_ID' of undefined

at playSong ((index):140)

at HTMLButtonElement.onclick











share|improve this question















I am trying to get a value from php file ,php file retrieve data from ORACLE DATABASE, to a script js this is the php file :



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = oci_parse($con, "SELECT s.song_path, s.song_id, s.TITLE, r.Artist_Name, a.artworkpath FROM songs s, artists r, albums a WHERE s.artist_id = r.artist_id AND a.album_id = s.album_id AND song_id='$songId'");
oci_execute($query);
$resultArray = oci_fetch_array($query);

echo json_encode($resultArray,JSON_FORCE_OBJECT);
}
?>


it works and successfully retrieve data from the tables.



The script that uses data:



<?php
$songQuery = oci_parse($con, "SELECT song_id from songs order by dbms_random.value");
oci_execute($songQuery);
$resultArray = array();

while(($row = oci_fetch_array($songQuery, OCI_BOTH)) != false) {
array_push($resultArray, $row['SONG_ID']);
}

$jsonArray = json_encode($resultArray, JSON_FORCE_OBJECT);
?>

<script>

$(document).ready(function() {
currentPlaylist = <?php echo $jsonArray; ?>;
audioElement = new Audio();
setTrack(currentPlaylist[0], currentPlaylist, false);
});


function setTrack(trackId, newPlaylist, play) {

$.post("includes/handlers/ajax/getSongJson.php", { songId: trackId }, function(data) {

var track = JSON.parse(data);
$(".trackName span").text(track.TITLE);
$(".artistName span").text(track.ARTIST_NAME);
$(".albumLink img").attr("src", track.ARTWORKPATH);

audioElement.setTrack(track.SONG_PATH);
audioElement.audio.play();
});

if(play == true) {
audioElement.audio.play();
}
}

function playSong() {
if(audioElement.audio.currentTime == 0) {
$.post("includes/handlers/ajax/updatePlays.php", { songId: audioElement.audio.currentlyPlaying.SONG_ID});
}

$(".controlButton.play").hide();
$(".controlButton.pause").show();
audioElement.audio.play();}


function pauseSong() {
$(".controlButton.play").show();
$(".controlButton.pause").hide();
audioElement.audio.pause();
}

</script>


All the functions work well except



(songId: audioElement.audio.currentlyPlaying.SONG_ID) 


It don't recognize SONG_ID which is a column from database retrieved in the php file (ajax/getSongJson.php)



PS: the (ajax/updatePlays.php) file is a php file that is for Updating DATA (PLAYS) when the user use playSong function when the current time = 0 so it increment the PLAY colomn in the database by 1



The update php file



<?php
include("../../config.php");

if(isset($_POST['songId'])) {
$songId = $_POST['songId'];

$query = OCI_parse($con, "UPDATE songs SET plays = plays + 1 WHERE song_id='$songId'");
oci_execute($query);
}
?>


This is the script file when I created a Audio Class, used in the script:



var currentPlaylist = ;
var audioElement;


function Audio() {

this.currentlyPlaying;
this.audio = document.createElement('audio');

this.setTrack = function(track) {
this.currentlyPlaying = track;
this.audio.src = track.SONG_PATH;
}

this.play = function() {
this.play();
}

this.pause = function() {
this.pause();
}

}


The error says :




Uncaught TypeError: Cannot read property 'SONG_ID' of undefined

at playSong ((index):140)

at HTMLButtonElement.onclick








javascript php json ajax oci






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 9 '18 at 9:31









marc_s

571k12811031252




571k12811031252










asked Nov 23 '18 at 12:01









oussama eddahrioussama eddahri

62




62








  • 3




    You need to post the relevant code here.
    – jeroen
    Nov 23 '18 at 12:02






  • 2




    And not as a picture, pelase
    – Mawg
    Nov 23 '18 at 12:04






  • 1




    Please go read How to Ask, Minimal, Complete, and Verifiable example, and meta.stackoverflow.com/questions/251361/… The code relevant to your problem belongs directly into your question, in text form. Please edit accordingly. (And keep the relevant part in mind.)
    – misorude
    Nov 23 '18 at 12:12










  • I have edited it thank you!
    – oussama eddahri
    Nov 23 '18 at 12:24










  • Please anyone have answer??
    – oussama eddahri
    Nov 23 '18 at 14:02














  • 3




    You need to post the relevant code here.
    – jeroen
    Nov 23 '18 at 12:02






  • 2




    And not as a picture, pelase
    – Mawg
    Nov 23 '18 at 12:04






  • 1




    Please go read How to Ask, Minimal, Complete, and Verifiable example, and meta.stackoverflow.com/questions/251361/… The code relevant to your problem belongs directly into your question, in text form. Please edit accordingly. (And keep the relevant part in mind.)
    – misorude
    Nov 23 '18 at 12:12










  • I have edited it thank you!
    – oussama eddahri
    Nov 23 '18 at 12:24










  • Please anyone have answer??
    – oussama eddahri
    Nov 23 '18 at 14:02








3




3




You need to post the relevant code here.
– jeroen
Nov 23 '18 at 12:02




You need to post the relevant code here.
– jeroen
Nov 23 '18 at 12:02




2




2




And not as a picture, pelase
– Mawg
Nov 23 '18 at 12:04




And not as a picture, pelase
– Mawg
Nov 23 '18 at 12:04




1




1




Please go read How to Ask, Minimal, Complete, and Verifiable example, and meta.stackoverflow.com/questions/251361/… The code relevant to your problem belongs directly into your question, in text form. Please edit accordingly. (And keep the relevant part in mind.)
– misorude
Nov 23 '18 at 12:12




Please go read How to Ask, Minimal, Complete, and Verifiable example, and meta.stackoverflow.com/questions/251361/… The code relevant to your problem belongs directly into your question, in text form. Please edit accordingly. (And keep the relevant part in mind.)
– misorude
Nov 23 '18 at 12:12












I have edited it thank you!
– oussama eddahri
Nov 23 '18 at 12:24




I have edited it thank you!
– oussama eddahri
Nov 23 '18 at 12:24












Please anyone have answer??
– oussama eddahri
Nov 23 '18 at 14:02




Please anyone have answer??
– oussama eddahri
Nov 23 '18 at 14:02












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446355%2fwhen-im-trying-to-retrieve-a-value-from-php-file-to-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446355%2fwhen-im-trying-to-retrieve-a-value-from-php-file-to-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo