view php/read/updateLink.php @ 10:5aa24c984a3b

if no code show entire response
author Henry S. Thompson <ht@markup.co.uk>
date Sat, 18 Feb 2017 12:28:36 +0000
parents 077b0a0a3e6d
children 385ddd7c4b55 84a412b8122c
line wrap: on
line source

<?PHP

$linkID = strval($_GET['linkID']);
echo $linkID;
$change = strval($_GET['change']);
echo $change;
$dir = strval($_GET['dir']);
echo $dir;
$userID = strval($_GET['userID']);
echo $userID;

include "../../../private/db.php";  

$pos = 0;
$neg = 0;

if($change == "pos")
{
	if($dir == "pos")
	{		
		$state = 1;
		$pos = 1;
	}
	else
	{
		$state = 0;
		$pos = -1;
	}
}
else
{
	if($dir == "pos")
	{		
		$state = -1;
		$neg = 1;
	}
	else
	{		
		$state = 0;
		$neg = -1;
	}
}

if($userID == "")
{
	$updateQuery = 'CALL b_changeLink('. $linkID  . ',' . $pos .',0,' . $neg .',0)';
	echo $updateQuery;
	$dataFinal = mysqli_query($link, $updateQuery);
}
else
{
	$check = 'CALL b_getStateID('. $userID .','. $linkID .')';  //select StateID from thumbstate where UserID = ' . $userID . ' and linkID = ' . $linkID;
	echo $check;
	$result = mysqli_query($link, $check) or exit( mysqli_error( $link ));
	$count=mysqli_num_rows($result);
	if($count==1){
		$rows=mysqli_fetch_array($result, MYSQLI_ASSOC);
		$stateID=$rows['StateID'];
		$stateQuery = "CALL b_updateThumbState($stateID,$state)";
	}
	else
	{
		$stateQuery = "CALL b_insertThumbState($userID,$linkID,$state)";
	}
	echo $stateQuery;
	
	mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
	include "../../../private/db.php"; 
	$stateFinal = mysqli_query($link, $stateQuery) or exit( mysqli_error( $link ));
}

//if email not zero, select userid from user where email=email
//insert into thumbstate null,userid,linkid,state (1,0,-1)

mysqli_close($link);

?>