PHP - Disable A Button For X Amount Of Time After Its Been Clicked?
Hi,
I am new to PHP world!! I am just trying to find a way to disable a button after its been clicked for lets say 5 minutes. I have searched google and haven't found what I am looking for. I just dont want the users to be able to refresh the page and the button becomes enabled again. any code examples with explanation or a simple tutorial will be much appreciated. Thanks Similar TutorialsIs there a way that you can disable a button at a set date and time?
For example, my work has a competition site running and I want to give people the option to change their weekly selections by clicking on an edit button up to 6pm on a certain Friday. After this time it either disappears or is just made inactive.
ie:
Comp 1 -> 'Edit' then disable after 6:00pm 2nd Jan
Comp 2 -> 'Edit' then disable after 6:00pm 9th Jan
Comp 3 -> 'Edit' then disable after 6:00pm 16th Jan etc....
I am not even sure where to start with this one.
Let's say I am buying a share for $10. If I sell the share on the same day BEFORE 3:30PM, it will be sold for $10, but if I keep the share past 3:30PM, I want the code to automatically add $1 (Taxes and such) once in the the price of the share in database, after that no matter how many days pass by, the price will remain the same.
I've thought about CRON jobs, but I have no idea how to make/use them or set them up.
Any direction or help is appreciated.
Hi guys, Im a newb here, so bear with me! Still learning the ropes. I want to delete all files from my server that are 6 hours old since being uploaded to the site. I believe i need a cron job? I currently have this script in its framework... Code: [Select] <?php //time interval for deletion to occur... $x = 30; //timestamp $current_time = time(); //the file you wish to delete $file_name = 'file.txt'; //timestamp $file_creation_time = filemtime($filename); //extract difference $difference = $current_time - $file_creation_time; //if difference = $x...then delete file if ($difference == $x) { unlink($file_name); } Would that work automatically or would it need a cron to run it? And how could i test it, that bit worries me. Many thanks. did some searching on the internet and didnt find much. i have created an online classifieds website and want all created listings to expire and delete after a certain amount of days. honestly i have no idea where to start with this implementation. cookies were the only thing that even crossed my mind... any ideas? btw each listing is stored in a table called ob_listings I have a PHP if() instruction. Within this if() instruction is a curl string which talks to a payment gateway. This gateway went down today, and caused my payment processing pages to hang. I am wondering if there is a way to make PHP abort a processing a instruction after a certain amount of time it runs? Hi, I'm not necessarily looking for code examples for my problem, (they are welcome but its not my explicit goal). I'm looking more for advice on how to go about tackling the problem i have. what i already have Currently i have a search getting results from a MySQL database. The results are ordered by one field that signifies their importance. Many of these results have the same value in this one column, and i have a switch statement to distinguish different content/styles for the different values. (there are just over 10 different bands) So the most important results are shown first and with a different style to the ones below it. (some bands have the same styling) what i need I would like to be able to randomize the results but only randomize the results within their specified bands. e.g. lets say theres 100 results in band A and 100 in band B. I still want everything in band A to be listed above band B, but i would like to randomly change the order of the results in band A and band B, (in this case once a week). I need to save the order of this randomization (client/server side?) for a week, then run the script again to set a new order. Now I would still class myself as an amateur php'er so at this stage i dont even know how i would go about separating the bands and randomizing their results independantly, let alone causing this functionality to run only once a week. So can anyone suggest a way i might go about this? I'm pretty stuck right now. Cheers I have a comment section. It is comprised of 3 major files. One file creates the form where you fill in your name and comment. Another file sends your comment to the DB. The third file displays the already existing comments on the page. You have the option to reply to the existing comments on the page. When you click the reply button I would like the comment text box to light up so the user knows its working but I have hit a brick wall.
This is the comment form the user actually types into:
<div id="comment-container" > <form id="comment_form" action="/comm_1/post_comment.php" method='post' onsubmit=" return validateForm()"> <table> <tr> <td id="error"></td> </tr> <tr> <td><textarea name="comment_body" id='comment_body' placeholder="Comment"></textarea></td> </tr> <?php if(!$username && !$userid): ?> <tr> <td><input type="text" name="name" class="input_style" placeholder="Name"/> <input type="submit" id="loginbtn" value="Or Login" onclick="window.location='/login_scripts/login.php'" /></td> </tr> <tr> <td><input type="email" name="email" class="input_style" placeholder="Email"/></td> </tr> <?php endif; ?> <?php if($username && $userid): ?> <input type="hidden" name="name" value="<?php echo htmlspecialchars($username) ?>"/> <input type="hidden" name="email" value="<?php echo htmlspecialchars($email) ?>"/> <?php endif; ?> <tr> <input type='hidden' name='parent_id' id='parent_id' value='0'/> <td><input type="submit" name="submitbtn" id="submitbtn" value="Add comment"/></td> </tr> </table> </form>This how the existing comments are displayed on the page: You can see on line 7 is the button to the reply to a comment. When this is clicked I need the "comment_body" from the above code to highlight. <?php function getComments($row) { echo "<li class='comment'>"; echo "<div class='aut'>".$row['author']."</div>"; echo "<div class='timestamp'>".$row['created_at']."</div>"; echo "<div class='comment-body'>".$row['comment']."</div>"; echo "<a href='#comment_form' name='replybtn' class='reply' id='".$row['id']."'>Reply</a></script>"; $q = "SELECT * FROM threaded_comments WHERE parent_id = ".$row['id'].""; $r = mysql_query($q); echo "</li>"; if(mysql_num_rows($r)>0) { echo "<ul>"; while($row = mysql_fetch_assoc($r)) { getComments($row); } echo "</ul>"; } } ?>I tried this with JS, but it does not work: $(function(){ $("a.reply").click(function() { var id = $(this).attr("id"); $("#parent_id").attr("value", id); $("#comment_body").focus(); }); }); Edited by ryanmetzler3, 26 January 2015 - 09:48 PM. Hello - I need a way to execute a stored procedure from a wordpress site with an external database where the stored procedure is housed. I am very limited in php code. All I know is from what little I have used My Custom Functions plugin. Please be very detailed. This stored procedure I run truncates and re-populates a number of tables I use for various reports. I am pulling data from the wp db and creating tables in the external db which make the data easier to read than through the wp meta data. The tables are housed in a separate db so as not to slow down the wp db. The hosting company does not allow 'Events' to run on the mySql db so I am left with figuring out how to create a cron job using a php file which would be the best. Aside from that, I thought a button on an admin page for execution would make it easier if I have to do it be hand. Thanks for your help. Ok, so I have a field in database called shutoff( a date when registrations will no longer be accepted for an event). How can I make it so that on the specified date, the register button will change to "no longer accepting Registrations". here is the form: Code: [Select] <?php // when displaying an article show a link // to see the article list if(isset($_GET['eventid'])) { ?> <div id="info " > <p>Date(s): <?php echo $startdate; ?><span class="klgjsa"> -</span> <?php echo $enddate; ?><br /> <span class="fgsdfg">Location:</span> <?php echo $location; ?><br /> <span class="adfasdf">Description</span><span class="adfdas">: </span><?php echo $description; ?> </p> <p> </p> <center> <table width="577" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="565" bgcolor="#C5C0B7" class="hjkh" scope="col"><?php echo $event; ?><font color='#C5C0B7'>...........................</font> <font size='-1'> <?php if ($accounttype =='Admin'){ echo "<a href='cofirmation.php'>Confirm Registrations </a><font color='#C5C0B7'>...</font><a href='quickregister.php?eventid=".$_GET['eventid']."'>Quick Registration</a><font color='#C5C0B7'>...</font><a href='viewregistered.php?eventid=".$_GET['eventid']."'>View Registrations</a>"; } ?></font></td> </tr> <tr> <td bgcolor="#999999" class="hjkh" scope="col"><table width="576" border="1" cellspacing="0" cellpadding="1"> <tr> <td width="91" bgcolor="#FFFFFF" scope="col"><?php $sql = mysql_query("SELECT * FROM Registration WHERE eventid=".$_GET['eventid']." LIMIT 1"); while($row = mysql_fetch_array($sql)){ $event= $row["event"]; $subevent1 = $row['subevent1']; $subevent2 = $row['subevent2']; $subevent3 = $row['subevent3']; $subevent4 = $row['subevent4']; $subevent5 = $row['subevent5']; $subevent6 = $row['subevent6']; $subevent7 = $row['subevent7']; $subevent8 = $row['subevent8']; $title1 = $row['title1']; $title2 = $row['title2']; $title3 = $row['title3']; $title4 = $row['title4']; $title5 = $row['title5']; $title6 = $row['title6']; $title7 = $row['title7']; $title8 = $row['title8']; $price1 = $row['price1']; $price2 = $row['price2']; $price3 = $row['price3']; $price4 = $row['price4']; $price5 = $row['price5']; $price6 = $row['price6']; $price7 = $row['price7']; $price8 = $row['price8']; $date1 = $row['date1']; $date2 = $row['date2']; $date3 = $row['date3']; $date4 = $row['date4']; $date5 = $row['date5']; $date6 = $row['date6']; $date7 = $row['date7']; $date8 = $row['date8']; //this will echo the contents of each db row as they are iterated in the loop ############################# if (!empty($title1)) { echo "<br/><strong>$title1</strong><br />$date1<br />$ $price1<br /><br />"; } if (!empty($title2)) { echo "<br/><strong>$title2</strong><br />$date2<br />$ $price2<br /><br />"; } if (!empty($title3)) { echo "<br/><strong>$title3</strong><br />$date3<br />$ $price3<br /><br />"; } if (!empty($title4)) { echo "<br/><strong>$title4</strong><br />$date4<br />$ $price4<br /><br />"; } if (!empty($title5)) { echo "<br/><strong>$title5</strong><br />$date5<br />$ $price5<br /><br />"; } if (!empty($title6)) { echo "<br/><strong>$title6</strong><br />$date6<br />$ $price6<br /><br />"; } if (!empty($title7)) { echo "<br/><strong>$title7</strong><br />$date7<br />$ $price7<br /><br />"; } if (!empty($title8)) { echo "<br/><strong>$title8</strong><br />$date8<br />$ $price8"; } } //etc etc ?></td> <td width="475" bgcolor="#FFFFFF" scope="col"><?php echo $description; ?></td> </tr> </table></td> </tr> </table> <table width="200" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="31" scope="col"><?php if (isset($_GET['eventid'])) { include('connect1.php'); $sql = "SELECT eventid FROM Registration WHERE eventid=".$_GET['eventid']." LIMIT 1"; $result = mysqli_query($dbcon, $sql) or die('error getting data'); echo "<table>"; $row = mysqli_fetch_array($result, MYSQLI_ASSOC); echo "<tr><td>"; echo "<form action='registration.php' method='get'><input type='hidden' name='eventid' value='{$row['eventid']}'><INPUT TYPE='submit' name='submit' VALUE='Register'></form>\n"; echo "</td></tr>"; echo "</table>"; } ?></td> </tr> </table></center> <p> </p> <table width="200" border="0" cellspacing="0" cellpadding="0"> <tr> <th scope="col"> </th> </tr> </table> <p><?php } ?> and here is where data is pulled: Code: [Select] $query = "SELECT event, description, startdate, enddate, location, subevent1, subevent2, subevent3, subevent4, subevent5, subevent6, subevent7, subevent8, price1, price2, price3, price4, price5, price6, price7, price8, shutoff FROM Registration WHERE eventid=".$_GET['eventid']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $startdate = $row['startdate']; $enddate = $row['enddate']; $location = $row['location']; $description = $row['description']; $event= $row["event"]; $subevent1 = $row['subevent1']; $subevent2 = $row['subevent2']; $subevent3 = $row['subevent3']; $subevent4 = $row['subevent4']; $subevent5 = $row['subevent5']; $subevent6 = $row['subevent6']; $subevent7 = $row['subevent7']; $subevent8 = $row['subevent8']; $title1 = $row['title1']; $title2 = $row['title2']; $title3 = $row['title3']; $title4 = $row['title4']; $title5 = $row['title5']; $title6 = $row['title6']; $title7 = $row['title7']; $title8 = $row['title8']; $price1 = $row['price1']; $price2 = $row['price2']; $price3 = $row['price3']; $price4 = $row['price4']; $price5 = $row['price5']; $price6 = $row['price6']; $price7 = $row['price7']; $price8 = $row['price8']; $date1 = $row['date1']; $date2 = $row['date2']; $date3 = $row['date3']; $date4 = $row['date4']; $date5 = $row['date5']; $date6 = $row['date6']; $date7 = $row['date7']; $date8 = $row['date8']; $shutoff = $row['shutoff']; does this make sense? it is in yyyy-mm-dd format(I believe that is correct...... This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=331164.0 Heres what i got... function printLB1 (){ $result = mysql_query("SELECT * FROM leaderboards ORDER BY CollegeFootballPoints DESC"); while ($row = mysql_fetch_object($result)) { $leaderboard[] = $row->Username; $leaderboardPoints[] = $row->CollegeFootballPoints; } $num = mysql_num_rows($reault); //I know from here to ................... needs to be in a var or echo or something. <tr> <td>1.</td> //This will auto increment too like i++ but i cna do that myself! <td>echo $leaderboard;</td> <td>echo $leaderboardPoints;</td> </tr> //Here......................................................... } I need to pull a table row per user. But i want to somehow do it once in a function and then ill echo the function into a table after the php stuff is done. Like i want to pull every a table row per user in the function. then display the function below that way i don't have to write a whole extra query and table row per person. If you understand please help if not please let me know where i can explain more. Thanks Hi, I am a newbie in PHP (about week and a half). I'm writing a website for myself right now. I've got a problem that I cannot solve. The website is about buying files with website custom balance. What I want to do is disable buy button if user bought this file b4. The is a table user_files that stores user id and file id. And another table that stores files data, ID name who uploaded date time ect.... What I'm trying to do, is disabling buy button if the user has already the file. This is what I've done : while ($row = $rocket->fetch()) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['uploader']; ?></td> <td><?php echo $row['uploadtime']; ?></td> <td><button <?php // Echo "disabled" if $row['id'] id is present in row2['file_id'] <<<<<<< Need to do this in a while. ?> ><a href="download.php?id=<?php echo $row['id']; ?>"></a><?php echo $row['price'] . "D$" ?></button></td> </tr> <?php } ?> What I can't do is check if the file id ($row['id']) is present in ($row2['file_id']), if yes echo "disabled";
I feel like a moron asking this question as it seems to be one of the most common things done with php but I cannot find a tutorial (probably because I don't know the correct wording to search under) on this specific thing.. Anyhow. I'm spitting out a list of the Titles of my test table like so (and its working as expected): <?php $posting_sql = "SELECT * FROM postings"; $posting_results = (mysqli_query($cxn, $posting_sql)) or die("Was not able to grab the Postings!"); while($posting_row = mysqli_fetch_array($posting_results)) { echo "<li><a href='posting_details.php'>$posting_row[title]</a></li>"; } ?> Now as you can see: <a href='posting_details.php'> I am calling a new page, and that page contains this: <h2><?php echo "$posting_row[title]"; ?></h2> <p><?php echo "$posting_row[description]"; ?></p> It's no surprise it's not working (with many variations etc), but I am only familiar with using <form> GET or POST, and these of course are not form elements, so I cant seem to call them the same way. My suspicion (and from the research data I could find) is that I need to pass values in my link: <a href='posting_details.php'> ... I could not get it to work, but I was trying variations like: <a href='posting_details.php?get[title&get[description]]'> but it seems like I am screwing things up even more by doing this.. Anyhow. If anyone could show me a tutorial that covers this specifically or some suggestions on the best approach to this would be much appreciated.. Hi All, How would I go about programming a HTML button that cannot be clicked on for two seconds after it loads? As part of a game I wish to stop people simply re-clicking the button and I think a delay of about two seconds would stop abuse of this (if they click it every two seconds then that's fine). I have read the manual for sleep() but it doesn't do exactly what I want - I want the rest of the page to load (and display), and the button to be grayed out for the two seconds, and then the button to be active. James I have dynamic images that have the "Like" button, it's basically like a wishlist. The way I want it to work is that when a user is not logged in, the 'Like' button will navigate them to a login popup (which I already made). Error: Code: [Select] No error, Im have trouble Having This Loop Select Only 2 Uploads At a Time. Code: Code: [Select] <?php //porperties $result = mysql_query("SELECT * FROM uploaded"); while($r=mysql_fetch_array($result)) { $link=$r["link"]; $name=$r["name"]; $type=$r["type"]; $size=$r["size"]; $date=$r["date"]; $id=$r["id"]; echo " The File $name Was Currently Updated<br> Size: $size<br> Type: $type<br> Date Updated: $date<br> Link: <a href='$link'>Download</a><br><br> "; } ?> Couldn't Think of a Good name For this,Sorry Code: [Select] ${$payment['amount']} using the $ next to it doesn't work I am using itinside double quotes, any way I can get that dollar sign right next to it? This for people buying stuff off my forum i want the amount to show right by the $ dollar sign And im working inside double quotes only Okay, I have a healing spell that allows people to regain stats when it's cast. But, how do I limit it so that they can't go over their maxhp? Here's what I have so far: $db->execute("UPDATE `users` SET `hp`=?, `mp`=?, `energy`=? WHERE `id`=?", array($player->hp + $healspell, $player->mp - $spell['mp'], $player->energy - $spell['energy'], $player->id)); What do I need to do in this to tell it to limit it to the maxhp but never going over it? $healspell is a random number, so it is quite possible to go over the maxhp at the moment. Thank you! If I knew what to call it I could have searched it. So I will just explain. I have a form that is pulling from a database to build the following. echo <input name='$row[id]' type='text' id='$row[id]' size=2>; This will build a page that has this <input name='22' type='text' id='22' size=2> <input name='54' type='text' id='54' size=2> This part works great. The problem is when I try to add it to the database. How can I insert variables that I don't know the names of? They will be something like $_POST[22] $_POST[54] and so on. I hope someone can understand my jibberish. I am sure there is a WAY better way to do this. Hi All, Im new to this forum but think its going to be a regular location for me for quite a while. Im very very new to php and the guy that was doing code for me is not responding to emails, so i thought id have a go myself...lol at the moment im going through the trial and error phase while learning. I have edited some of the code he has put on the site to create a new look. the original page: http://www.ridersguide.co.uk/county_accommodation.php?county=4; the one im trying:http://www.ridersguide.co.uk/county_accommodation2.php?county=4; The new bit is to add a preview of the text for the page. echo $row[ad_text]; the code above brings up all the text but i only want to show the first 4 or 5 lines. Is this possible in php? Any help appreciated Neil |