Hi there i'm trying to get data-id from url and use this id to insert into database, to make like dislike system.
data-id="1" it is user id.
The link look like this:
<a data-fav="<?php echo $_SESSION['LANG']['favorite']; ?>" data-fav-active="<?php echo $_SESSION['LANG']['favorited']; ?>" class="favorite favoriteIcon" data="<?php echo $key['id']; ?>" data-id="<?php echo $key['user_id']; ?>" data-token="<?php echo $key['token_id']; ?>">
PHP source
some more information: the link is inside of the message that users write, when someone clicks like message, it goes to function call favorites
public function favorites() {
/*
* ----------------------------------------------------------------------------
* Add, Remove Favorites
* @$active :"Check to see if the user has already added prior to Favourites"
* @verified : "Check if the publication exists"
* ----------------------------------------------------------------------------
*/
$active = self :: favsUser( null, $_SESSION['authenticated'], $_POST['id'] );
$verified = self :: checkPost( $_POST['id'], $_POST['token'] ) ? 1 : 0;
if( $verified == 1 && empty( $active ) )
{
$_idPost = (int)$_POST['id'];
$_sql = $this->db->prepare("SELECT user FROM posts WHERE id = :id");
$_sql->execute( array(
':id' => $_idPost
)
);
$response = $_sql->fetch( PDO::FETCH_OBJ );
/** If not exists, insert new record **/
$sql = $this->db->prepare("INSERT INTO favorites VALUES( null, ?, ?, '1', '".$this->_dateNow."' );");
$sql->bindValue( 1, $_GET['data-id'], PDO::PARAM_INT );
$sql->bindValue( 2, $_POST['id'], PDO::PARAM_INT );
$sql->execute();
if( $sql->rowCount() != 0 ) {
if( $response->user != $_SESSION['authenticated'] ) {
/* Send Interaction */
self :: sendInteraction( $response->user, $_SESSION['authenticated'], $_idPost, 3 );
}
return( 1 );
}
}
if( $verified == 1 && !empty( $active ) && $active[0]['status'] == '1' )
{
/** If exists, update status to Delete/Trash **/
$sql = $this->db->prepare("UPDATE favorites SET status = '0' WHERE id_usr = ? && id_favorite = ? ");
$sql->bindValue( 1, $_SESSION['authenticated'], PDO::PARAM_INT );
$sql->bindValue( 2, $_POST['id'], PDO::PARAM_INT );
$sql->execute();
if( $sql->rowCount() != 0 )
{
return( 2 );
}
}
else if ( $verified == 1 && !empty( $active ) && $active[0]['status'] == '0' )
{
/** If exists and status == Delete/Trash, update status to Active **/
$sql = $this->db->prepare("UPDATE favorites SET status = '1' WHERE id_usr = ? && id_favorite = ? ");
$sql->bindValue( 1, $_SESSION['authenticated'], PDO::PARAM_INT );
$sql->bindValue( 2, $_POST['id'], PDO::PARAM_INT );
$sql->execute();
if( $sql->rowCount() != 0 )
{
return( 3 );
}
}
return false;
$this->db = null;
}
MYSQL starcture
TABLE favorites
COLUMNS: id (automatic), id_usr (user id from data-id that we need to take from url ), id_post (if of post all set), date (date)
Thank you.