if i click add to playlist button the alert was shown based on the hello.php file [ just echo message ], here how can i save my id and name into the hello.php page like cart page, if i click add to playlist button i need my id and name save into the hello.php page.
OK, so from that it seems that your “add to playlist” functionality isn’t implemented either, save for popping up an alert when you click the button.
I would suggest a browse down through the forum or general search - implementing a shopping cart function from scratch is a bit of a wide-ranging topic for a forum question. Forum questions are normally for helping out when you’ve done most of the coding and are having specific issues or to get ideas on how to implement a specific part, rather than the whole thing from scratch.
What’s your level of programming experience? That is, how familiar are you with PHP in general, and data handling? It’s not a difficult thing to do from what I can see, you already know what fields you need to store, so it’s just a case of designing somewhere to store them and writing the code. You could start by altering your pop-up to show the data that you want to store, rather than just the fixed message of your test code.
Is the data being passed into, and out of, cart.php? Add some alerts in your JS to see what is happening.
You might also want to browse around the JavaScript section of the forum and see whether anything in there helps.
These two lines
var voice_id = $("#voice_id").val();
var voice_name = $("#voice_name").val();
rely on you having page elements with an id of voice_id and voice_name respectively, which I don’t see that you have in the code you posted. In any case, it wouldn’t be appropriate to add them as ids because your initial screen shots shows you have more than one item in your list, and ids have to be unique.
As you pass in voice_id to the addCart() function, why don’t you just use that value? There’s no need to pass the id and the name into your PHP code, as the PHP can easily retrieve the name from the database if it needs it.
If you call cart.php directly from the browser, it’s not going to have any values to display, because they are passed in by your JS call. I can’t see your screen shot as it’s too small, but it looks as if it is showing empty values, but also the address bar shows you opened it directly, and the summary at the bottom suggests that it was called with “GET”, so of course the $_POST array will be empty.
I tried your code in a short page and it worked correctly for me. The only thing I changed is that I removed your references to $row for the values, and put hard-coded values in, because my test code doesn’t connect to a database. So, I suspect that’s the problem.
The first question would then be - if you right-click, “view source” and look at your button code, does it have the correct values that are coming from the $row result set? And are all the quotes in the correct place? My test code line looks like this: