if(!isset($_POST['JoinFaction'])) {
echo '<form method="post" action="'.$page_name.'"><dl id="sample" class="dropdown" align="left">'
.'<dt><a href="#"><span>Recruiting Factions ['.$numrows.']</span>'
.'</a></dt><dd><ul>';
while($faction_re = mysql_fetch_array($sql)){
echo '<li><a href="#">'.$faction_re['f_name'].''
.'<span class="value">'.$faction_re['f_id'].'</span></a></li>';
}
echo '</ul></dd></dl></td>'
.'<td class="faction_bgcolour" align="center"><input type="image" '
.'name="JoinFaction" value="JoinFaction" width="54" height="45" '
.'src="images/global/game/faction/join_faction.png" /></td></form>';
//get output as a variable to use in later code
echo $selected_faction = '<span id="result"></span>';
} else { $selected_faction = '<span id="result"></span>';
echo '<div class="faction_text">Joined: '.$selected_faction.'.</div>';
}
when I:
echo $selected_faction;
in the if statement, it gets the right faction value (i'm using custom jquery drop down boxes by the way here).
The problem is that this id is not being passed to the else statement where i can update the database. I'm really not sure how I would pass the id on to the else statement.
echo $selected_faction is blank in the else clause
Any help would be greatly appreciated.
You're going to need to send the content of that div back to your server with AJAX.
You could start learning here: http://api.jquery.com/category/ajax/
I suppose a good starting point might be: http://api.jquery.com/jQuery.post/
Related
How do i disable and enable an anchor tag based on order_status condition? I want to make my receipt button only be able to click when the order_status been updated to ($irow['order_status'] == 5. It would be much appreciated if you all can provide me a code demo to show me how should I implement this using php. Thanks!
I tried the below codes but it wasn't working. It shows the error of Parse error: syntax error, unexpected 'order_id' (T_STRING). I do not know why does this happens. Can you guys give me a help to implement this?
<?php
if($order_status == 5){
print ' <a id="receiptbtn" target="_blank"
href="
receipt.php?order_id=<?php echo $row['order_id']; ?>"
class="btn addtocart" style="font-size: 12px;"><span class="iconify" data-icon="bx:bx-download" data-inline="false"></span> Receipt</a>';
}
else{
print 'Receipt';
}
?>
You're already in <?php execution mode, you can't use <?php echo to include a string. <?php is being treated as literal text in the string, and the ' in $row['order_id'] is ending the string that you're printing.
Use the string concatenation operator to combine a variable with the string literal.
To disable a link use href="#". href="" means to reload the page.
<?php
if($irow['order_status'] == 5){
print ' <a id="receiptbtn" target="_blank"
href="receipt.php?order_id=' . $row['order_id'] . '"
class="btn addtocart" style="font-size: 12px;"><span class="iconify" data-icon="bx:bx-download" data-inline="false"></span> Receipt</a>';
}
else{
print 'Receipt';
}
?>
a bit of a weird one, but I have figured out how to use glob to display a list of images, and now I want to add a button under each image that would let you delete each image individually, I think I just need to use unlink, but whenever I try it just seems to delete every file on the server!:')
Here is the code I have so far:
<?php
// This sets the variable $filelist, and get it to search the specificied levels of wildcards for jpg, png, JPG, and PNG using glob:
$filelist = glob('{*.jpg,*/*.jpg,*/*/*.jpg,*/*/*/*.jpg,*/*/*/*/*.jpg,*/*/*/*/*/*.jpg,*.png,*/*.png,*/*/*.png,*/*/*/*.png,*/*/*/*/*.png,*/*/*/*/*/*.png,*.JPG,*/*.JPG,*/*/*.JPG,*/*/*/*.JPG,*/*/*/*/*.JPG,*/*/*/*/*/*.jpg,*.PNG,*/*.PNG,*/*/*.PNG,*/*/*/*.PNG,*/*/*/*/*.PNG,*/*/*/*/*/*.PNG}', GLOB_BRACE);
// This filters the above into date order from newest to oldest:
usort($filelist, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
// This is how I now output the data, basically looks for each value of $filelist and sets it as $link, then outputs this and concatenates it with itself as a href and a background-image:
echo '<div class="thumbnail-grid">';
if($filelist){
foreach($filelist as $link){
echo '<div class="tile-container">';
echo '<a style="background-image: url('.$link.');" class="photo-link" href="'.$link.'"><i class="fas fa-link"></i></a>';
// This adds in a delete button:
echo '<form method="post"><input style="cursor: pointer;" name="delete" type="submit" value="DELETE"></form> ';
echo '</div>';
// This is the script that should be doing the unlinking:
if(isset($_POST['delete']))
{
unlink($link);
}
}
}else{
echo ' No images found.';
}
echo '</div>';
Hope this all makes sense/isn't asking too much!
Many thanks, Jack.
This isn't very secure as anyone can send a POST variable with a filename and delete it.
But as an example, you can loop through the files and give the delete button a value of the filename and then when you check for the posted delete button delete the file.
// This is the script that should be doing the unlinking:
if(isset($_POST['delete'])){
unlink($_POST['delete']);
}
if($filelist){
foreach($filelist as $link){
echo '<div class="tile-container">';
echo '<a style="background-image: url('.$link.');" class="photo-link" href="'.$link.'"><i class="fas fa-link"></i></a>';
echo '<form method="post">
<input style="cursor: pointer;" name="delete" type="submit" value="'.$link.'">
</form> ';
echo '</div>';
}
}else{
echo ' No images found.';
}
I'm currently in the process of making a social network. I'm am displaying all registered users with the following code.
Is there a better way of doing this?
<?php
$query = $db->query("SELECT * from members");
while($r = $query->fetch()) {
echo '<div class="col-sm-6 col-md-6 col-lg-3 membersGrid">';
echo '<div class="profileThumb">';
echo '<img width="130" height="130" src="'.$r['profile_pic'].'"/><br>';
echo $r['username'], '<br>';
echo $r['country'], '<br>';
echo '<a class="viewProfile" href="profile.php"><button>View Profile</button></a>';
echo '</div>';
echo '</div>';
}
?>
I'm trying to create a link to the individual profile pages for each users. Currently each link is within the above while loop, however, I'm a little uncertain of how to link to the relevant profile page. I'm guessing I have to append a variable to the URL. Any guidance would be greatly appreciated.
echo '<a class="viewProfile" href="profile.php"><button>View Profile</button></a>';
It would depend on how your profile.php page is handling the GET variable that determines the profile of the person you are showing. Let's say that the variable is called id and that you have a row in your members table also called id (which acts as the unique key), then your anchor tag would look like:
echo '<a class="viewProfile" href="profile.php?id=' . $r['id']. '"><button>View Profile</button></a>';
First retrieve the user_id of the user from the database as you are doing with the query. Then give this id to the profile link as:
echo '<a href="profile.php?userid=' . $user_id . '>Linkname</a>';
Then in profile.php get this variable through:
$id = $_GET['userid'];
This way you can show the relevant user's profile in the profile.php.
Hope you might get the idea to work on.
If you are producing a list of links to user profiles then there are a couple of different options:
You can either append a $_GET variable to the end of your link as previously mentioned by Lloyd
echo '<a href="profile.php?if=' . $r['id'] . '">';
or you can send a $_POST variable; the easiest way to do this would be to create a list of forms:
<?php
$query = $db->query("SELECT * from members");
while($r = $query->fetch()) {
echo '<div class="col-sm-6 col-md-6 col-lg-3 membersGrid">';
echo '<div class="profileThumb">';
echo '<img width="130" height="130" src="'.$r['profile_pic'].'"/><br>';
echo $r['username'], '<br>';
echo $r['country'], '<br>';
echo '<form action="profile.php" method="post">';
echo '<input type="hidden" value="' . $r['id'] . '" />';
echo '<input type="submit" value="View Profile" />';
echo '</form>';
echo '</div>';
echo '</div>';
}
?>
Sorry if I've misread your question, hope this helps.
I am having a problem with this code
<?php
echo '<div class="post_note2">
<b>'.$lang['RENEW_SUCCESS'].'</b></div><br /><span class="orange"><b>HOME|VIEW AD</b></span>';
}
}?>
for some reason when the VIEW AD link is clicked it doesn't build it properly and still contains the php code in the link rather than the link to the actual ad page. is it an issue with an echo in an echo ?
I'm sure this isn't quite difficult to solve but I have been trying for far to long on my own and cant get it.
Thanks, any help would be great.
You actually had it right in the first part of your string. You can't have and echo statement inside of another echo statement. Use concatenation throughout your string:
<a href="' . $adurl . '"
You have two extra brackets at the end and php text inside your echo.
<?php
echo '
<div class="post_note2">
<b>'.$lang['RENEW_SUCCESS'].'</b>
</div>
<br />
<span class="orange">
<b>
HOME | VIEW AD
</b>
</span>';
?>
All fixed given that $adurl is defined.
This
<?php echo $adurl; ?>
Should be
' . $adurl . '
i.e.
echo '<div class="post_note2"><b>'.$lang['RENEW_SUCCESS'].'</b></div><br /><span class="orange"><b>HOME|<a href="'.$adurl.'>VIEW AD</a></b></span>';
Okay, I think what I've got is pretty simple for an experienced web dev person. Right now, this this is the index page for State of Debate, my debate website. From the code below, you can see that I have a while loop to echo out each debate, which corresponds to a "did" in the mySQL database. What I need to do, for upvote/downvote purposes, is to get each "did" that goes through the loop. I would then pass it to the "upvote.php" and "downvote.php".
I've tried a foreach loop, although that could be the answer and I just didn't find it. I've used $_SESSION['did'] = $row['did'] and all that does is pass the last did to the PHP page.
Any help is appreciated. And please ask if you need more info.
<?php
$result = mysql_query("SELECT did,debatetitle FROM debates");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><a href='/debatepage.php?did=" . $row['did'] . " '>" . $row['debatetitle'] . "</a></td>";
?>
<tr><td>
<a href="upvote.php" onClick="alert('You have given this item a thumbs up! You can change your vote, or leave it how it is.')"; onMouseOver="return changImage()" onMouseOut= "return changImageBack()" ><img
name="jsbutton2" src="Graphics/thumbs-up-unclicked.jpeg" width="75" height="75" border="0"
alt="javascript button"></a>
<script type="text/javascript">
function changImage()
{
document.images["jsbutton2"].src= "Graphics/thumbs-up.jpeg";
return true;
}
function changImageBack()
{
document.images["jsbutton2"].src = "Graphics/thumbs-up-unclicked.jpeg";
return true;
}
</script>
<a href="downvote.php" onClick="alert('You have given this item a thumbs down! You can change your vote, or leave it how it is.')"; onMouseOver="return changeImage()" onMouseOut= "return changeImageBack()" ><img
name="jsbutton1" src="Graphics/thumbs-down-unclicked.jpeg" width="75" height="75" border="0"
alt="javascript button"></a>
<script type="text/javascript">
function changeImage()
{
document.images["jsbutton1"].src= "Graphics/thumbs-down.jpeg";
return true;
}
function changeImageBack()
{
document.images["jsbutton1"].src = "Graphics/thumbs-down-unclicked.jpeg";
return true;
}
</script>
</tr></td>
<?php
echo "</tr>";
}
echo "</table>";
change this:
<a href="upvote.php" onCli....
to
<a href="upvote.php?did<?PHP echo $row['did']"; ?> onCli
and the same with downvote link.
To use the variable in upvote.php:
<?PHP
echo $_GET['did'];
?>