view php/read/updateLink.php @ 43:dbc006408d2b

ASSUMES we have SetEnv PHP_VALUE "include_path =.:/var/test/private:/var/test/ywww:/usr/share/php" in apache2/.../test.conf use dl(...) for debug logging, defined in dlog.php use doAmazonRequest in amazonBookSearch use ../private/web.php (q.v., not in mercurial) for Aserver and Aassociates Started by updating from 40:c24ae74bf6d5, i.e. just before the bug on the main line
author Charlie Root
date Sat, 05 Jan 2019 18:00:10 -0500
parents f024f2f08994
children a67bf725e87b
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="";
if (isset($_GET['userID'])) {
    $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);

?>