PHP Post value receive error

purchase.php pages post the value,

   <?php
//fetch_data.php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include('database_connection.php');

if(isset($_POST["action"]))
{

	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$total_row = $statement->rowCount();
	$output = '';
	if($total_row > 0)
	{
		foreach($result as $row)
		{
			$output .= '
			<div class="col-sm-3 col-lg-4 col-md-3">
				<div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;">
					<audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;">
						<source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive">
					</audio>
					<p align="center"><strong> '. $row['voice_name'] .'</strong></p>

					<p style="font-size: 12px;">
					Id		      : '. $row['voice_id'].' <br />
					Name		      : '. $row['voice_name'].' <br />
					Gender		      : '. $row['voice_gender'].' <br />
					Genres 			  : '. $row['voice_genres'].' <br />
					Voice Modulation  : '. $row['voice_voice_modulation'].' <br />
					Languages		  : '. $row['voice_languages'].' <br />
					Jingle Moods	  : '. $row['voice_jingle_moods'].' <br />
					Ivr 			  : '. $row['voice_ivr'].' <br /> </p>
					
					<button type="button" class="btn btn-primary" style="padding: 5px 83px 5px 83px;" data-voice-id="'.$row["voice_id"].'" data-voice-name="'.$row["voice_name"].'">Add to Playlist</button>

				</div>

			</div>
			';
		} 
	}
	else 
	{
		$output = '<h3>No Data Found</h3>';
	}
	echo $output;
}
?>

<script>

	$('.btn').on('click',function() {
		// var voice_id 	= $("#voice_id");
		// var voice_name  = $("#voice_name");

		var voice_id = $(this).data("voice-id");
		var voice_name = $(this).data("voice-name");

		$.ajax({
			type 	 : "POST",
			url  	 : "my_cart.php",
			datatype : "text",
			data	 : { voice_id: voice_id, voice_name: voice_name },
			// data	 : "voice_id="+voice_id+"&voice_name="+voice_name,



			success: function(data)
			{
				// console.log(data);
				//console.log('success',data);
				//$('#result').html(response);
				
			}
		});
	});

</script>

I need to pass voice_id and voice_name to my_cart.php,

my_cart.php:

<?PHP
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Get details from fetch_data.php
$voice_id = '';
$voice_name = '';
if(isset($_POST['voice_id']) && isset($_POST['voice_name']))
{
    $voice_id   = $_POST['voice_id'];
    $voice_name = $_POST['voice_name'];
}

    echo "$voice_id & $voice_name";

?>

The value from purchase.php page send value, but the my_cart.php not receiving the post value.

Sponsor our Newsletter | Privacy Policy | Terms of Service