I am using a modal dialog opener that I want to open when a user clicks one of a few available buttons. The buttons all have a different “artist_id” associated with them. When a button is clicked, I also have a php script that should run and put the user id and artist id in a table that keeps track of the “liking” relationships. Below is the relevant code:
index.php:
//script
<script>
$(function() {
$( "#dialog-modal" ).dialog({autoOpen: false, height: 250, width: 400, modal: true});
$( "#opener" ).click(function() {
$( "#dialog-modal" ).dialog( "open" );
$.get('/like_artist.php', {artist_id : $(this).data('artist_id')})
.done(function(data) {
alert("Data Loaded: " + data.artist_id);
});
});
});
</script>
//button:
<button type="button" id="opener" data-artist_id="1">Play My City</button>
//dialog content (I would like to have this change based on the button clicked):
<div id="dialog-modal" title="Basic dialog">
<p>You have just liked ...</p>
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
like_artist.php: takes a user id and artist id and puts them in the relationship table user_artists
<?php
session_start();
require_once "database.php";
db_connect();
require_once "auth.php";
$current_user = current_user();
include_once("config.php");
$artist_id = $_GET['artist_id'];
$user_id = $current_user['id'];
$query = "INSERT INTO `user_artists`
(`artist_id`, `user_id`)
VALUES
(''$artist_id', '$user_id')";
$result = mysql_query($query);
?>
The alert I have put in the top script is there to see if I am getting the correct artist_id from the data-artist_id property, but it is not returning anything.
Thank you for your help!
You’re not returning (echoing) anything in
like_artist.php, naturally your AJAX response will be empty as well.Then you’ll have to decode it on the frontend.