加入组按钮php& mysql

时间:2017-04-15 13:16:06

标签: php mysql button

我想在点击它时创建按钮制作2个目标:
 1.让此用户加入此群组

(add user_id and gro_id in table groups_has_user)

2.如果用户已加入

,则更改按钮值
CREATE TABLE IF NOT EXISTS `groups_has_user` (
          `Groups_gro_id` int(11) NOT NULL,
          `users_user_id` int(11) NOT NULL,
          PRIMARY KEY (`Groups_gro_id`,`users_user_id`),
          KEY `fk_Groups_has_users_users1_idx` (`users_user_id`),
          KEY `fk_Groups_has_users_Groups1_idx` (`Groups_gro_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

<?php
  if(isset($_POST['join'])){
    require '_database/database.php';
    mysql_query("INSERT INTO groups_has_user(users_user_id, Groups_gro_id)VALUES('$users_user_id','$groid')");
  }
?>

<form action="group.php?gro=<?php echo $groid;?>" method="post" enctype="multipart/form-data" id="UploadForm">
  <button type="submit" class="btn btn-danger" name="join">join us</button>
</form>

1 个答案:

答案 0 :(得分:0)

嗯,懒惰的解决方案......

将数据插入mysql存储会话中的<form1> <div class="pagination"> <a id="pageOne">1</a> <a id="pageTwo">2</a> <a id="pageThree">3</a> </div> </form1> <script> links = document.querySelectorAll("a") links.forEach(function (item) { item.addEventListener('click', function () { //reset the color of other links links.forEach(function (item) { item.style.backgroundColor = '#fff' }) // apply the style to the link this.style.backgroundColor = '#ffcce9' }); }) </script>。像

user_id

现在检查用户是否已加入。

<?php
  if(isset($_POST['join'])){
    require '_database/database.php';
    $_SESSION['user_id'] = $users_user_id;
    mysql_query("INSERT INTO groups_has_user(users_user_id, groups_gro_id)VALUES('$users_user_id','$groid')");
  }
?>

我希望你知道如何检查用户。现在,你从这里开始。

PS:请注意SQL INJECTIONs。使用<?php $result = mysql_query("SELECT * FROM groups_has_user WHERE users_user_id = $_SESSION['user_id']"); if(isset($result)){ ?> <h3>You have joined this group</h3> <?php }else{ ?> <form action="group.php?gro=<?php echo $groid;?>" method="post" enctype="multipart/form-data" id="UploadForm"> <button type="submit" class="btn btn-danger" name="join">join us</button> </form> <?php } ?> mysqli