<?php
error_reporting(E_ALL);
$dbh = new PDO("mysql:host=localhost;dbname=mmaaaco_cjorgensen", "mmaaaco_cjorgen", "TD}*;vhNWkT$");
$submit = $_POST['submit'];
if ($submit == 'Insert'){
	$artist = $_POST['artist'];
	$cd = $_POST['cd'];
	$check = $dbh->prepare("select count(id) from practice_artists where artist  = ?");
	$check->bindValue(1,$artist);
	$check->execute();
	print_r($check->errorInfo());
	$checkrow= $check->fetch();
	if ($checkrow[0] < 1){
	$inssql= $dbh->prepare("insert into  practice_artists (artist) values (?)");
	$inssql->bindValue(1,$artist);
  $inssql-> execute();
	}
	$getartistid = 	$dbh->prepare("select id from practice_artists where artist  = ?");
	$getartistid->bindValue(1,$artist);
	 $getartistid->execute();
	 	$getartistidrow= $getartistid->fetch();
		$artistid = $getartistidrow[0];
		
		
		
		$check = $dbh->prepare("select count(id) from practice_cds where title  = ?");
	$check->bindValue(1,$cd);
	$check->execute();
	$checkrow= $check->fetch();
	if ($checkrow[0] < 1){
	$inssql= $dbh->prepare("insert into  practice_cds (title) values (?)");
	$inssql->bindValue(1,$cd);
  $inssql-> execute();
	}
	
		$getcdsid = 	$dbh->prepare("select id from practice_cds where title  = ?");
	   $getcdsid->bindValue(1,$cd);
	 $getcdsid->execute();
	 	$getcdsidrow= $getcdsid->fetch();
		$cdsid = $getcdsidrow[0];
			$ins = $dbh->prepare("insert into practice_holder (cdid,artistid) values (?,?)"); 
	$ins->execute(array($cdsid,$artistid));
	//insert 
//get $cd     
//check to see if exists
//if not insert
//either way you need to get the id from the cds table
//insert into holder table  

	
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="index.php" method="post">
Artist <input name="artist" type="text">
Cd <input name="cd" type="text">
<input name="submit" type="submit" value = "Insert">
</form>
</body>
</html>
