ColourfulConnor
Member
- Dec 7, 2016
- 65
- 5
Basically the CMS I'm using allows the user to create Tags but I was not given a table for it so I created my own and to the most part it actually worked, the player can now create a tag BUT I don't think that tag is being assigned to that player, for some reason when the player selects the "My Tags" page, it does show the tag but when clicking the "Tags" page it displays, here is the code for the "My Tags"
No Errors are Appearing.
"My Tags"
Create Tag
Screenshots:
No Errors are Appearing.
"My Tags"
Code:
<div id="mytags" style="display:none;">
<?php
$getTags = mysql_query("SELECT * FROM user_tags WHERE user_id = '". $_SESSION['user']['id'] ."' ORDER BY id DESC LIMIT 15");
while($row = mysql_fetch_array($getTags)) {
if(mysql_num_rows($getTags) < 1) {
echo '<div class="noTags">You have not yet added any tags!</div>';
} else {
echo '<div class="tag">
<form action="" method="POST" name="delete" style="margin-top:5px;margin-right:0px;float:left;">
<input type="text" id="id" name="id" value="'.$row['id'].'" hidden="hidden"/>
<input type="submit" class="inputDelete" value="" name="delTag"/>
</form>'.
$row['tag'].'
</div>';
if(isset($_POST['delTag'])) {
$select = mysql_query("SELECT * FROM user_tags WHERE user_id ='". $_SESSION['user']['id'] ."'");
$fetch = mysql_fetch_assoc($select);
if($row['user_id'] != $_SESSION['user']['id']) {
echo 'You can not delete tags that are not yours!';
} else {
$del = mysql_query("DELETE FROM user_tags WHERE id = '".$_POST['id']."' AND
user_id = '".$_SESSION['user']['id']."'") or die(mysql_error());
if($del) {
header('Refresh:0');
echo '<script type="text/javascript">
document.getElementById("randomtags").style.display = "none";
document.getElementById("mytags").style.display = "block";
document.getElementById("addtag").style.display = "none";
</script>';
}
}
}
}
}
?>
</div>
Create Tag
Code:
<div id="addtag" style="display:none;">
<form action="#" method="POST">
<input type="text" name="tag-name" placeholder="Voeg een tag toe" style="float:left;width:59%"/>
<input type="submit" name="addTags" value="Voeg toe" style="width:32.5%;float:right"/>
</form>
<?php
if(isset($_POST['addTags'])) {
echo '<script type="text/javascript">
document.getElementById("randomtags").style.display = "none";
document.getElementById("mytags").style.display = "none";
document.getElementById("addtag").style.display = "block";
</script>';
if(empty($_POST['tag-name'])) {
echo '<font color="red">You did not tag!</font>';
} else {
$user = mysql_real_escape_string(stripslashes(addslashes($_SESSION['user']['id'])));
$tag = mysql_real_escape_string(stripslashes(addslashes(htmlspecialchars($_POST['tag-name']))));
$add = mysql_query("INSERT INTO user_tags (user_id, tag) VALUES ('".$user."', '".$tag."')") or die(mysql_error());
if($add) {
echo '<font color="green">Tag has been Added!<a href="">Refresh</a></font>';
} else {
echo '<font color="red">Whoops! Something went wrong. Try again.</font>';
}
}
}
?>
</div>
</div>
</div>
Screenshots:
Add Tag
Community Tags
My Tags
Tag Database
Community Tags
My Tags
Tag Database