Jump to content

PNewCode

Members
  • Posts

    315
  • Joined

  • Last visited

Everything posted by PNewCode

  1. @Barand thank you. Can you tell me how I would subtract the current from the value in the database. For example Current time is 2024-01-29 09:41:36 and the column "Visited" is 2024-01-28 09:41:36 Then I would echo "Last Visited 1 Day Ago"
  2. Hello. I have 2 columns called "visited" and "created_at" I want to get the time between the two (visited date changes each time a person visits their login) So the goal is to echo, for example Created At Jan 27 2024 09:41AM ------ Visited At Jan 29 2024 09:41AM Last visit was 2 days ago I can't seem to get this right. Any help is appreciated. This is what I have so far $date1 = $row["date_format(created_at, '%b %e %Y %h:%i%p')"]; $date2 = $row["date_format(visited, '%b %e %Y %h:%i%p')"]; $datediff = $date1 - $date2; echo "<b>$datediff</b>"; However, the following will echo them if I have it like the following, though thats each date and no subtraction echo '.$row["date_format(visited, '%b %e %Y %h:%i%p')"].'; echo '.$row["date_format(created_at, '%b %e %Y %h:%i%p')"].'; Also I have this $sql = "SELECT date_format(visited, '%b %e %Y %h:%i%p'),date_format(created_at, '%b %e %Y %h:%i%p')";
  3. Nevermind. I'm WAY off my mark on what I need to do. Moderators, feel free to delete this thread. My original question isn't even close to what I thought I needed to do. My appologies yall
  4. I tried to edit my original but the option wasn't there. So it looks like I just need to remove the ?si= and whatever is after that
  5. I found somewhere that someone used si=([\w_]*) so I tried to add that in what I have but zero luck with it.
  6. @Andou thank you, however The regex I have now works. I'm not getting any errors. But it's not doing what it needs to do because some links are like the example I gave instead of the other types. the "si" part is what needs to be added and those are also more than 11 characters I looked up a lot of docs on regex and the link you gave too. But that will have to be for when I can learn from scratch instead of just adding to what I have. Though I fully plan to do that asap
  7. Hello. I have the following that works great for youtube links. I'm using this to show a thumbnail with the help of some other coding that works awesome. However there needs something added. I tried to alter this in many various way but I don't seem to get a grasp on how to split it up right to add to it. The following is what I have. $url = "$ytvideo1"; parse_str( parse_url( $url, PHP_URL_QUERY ), $vid ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); $youtube_id = $match[1]; And it works for ALMOST all of the youtube links. However if I have one that is like Then it doesn't work. I tried to add the "si" in there in multiple ways but not sure how. This is the only type of link that is stumping me so far Any thoughts on how to alter what I have to make it work? PS, I know it's adding my examples as links. I'm sorry. I couldn't find how to add those without it auto linking.
  8. The second part of my question I resolved using if(!isset($_POST['number_entered'])){
  9. @Barand Thats perfect. Thank you very much!!! So I have an added question to this, I'm not sure if I should have a different thread though so if I should have asked a new question then I'm sorry. The game itself is just a random number game. I got this from a different page an I didn't create it. What I would like to do is have it so the form is gone, and the links appear if they got it right or wrong. This way they only play once on the same page. Right now, this will work correctly for the game itself, and show the results at the bottom. The task is to REPLACE the game with the results showing, instead of just undernieth it. Can't be a different page or redirect because the results will need to show first, and the form for the game will have to be removed. I have tried several scripts to just disable the button after the click with javascript but it wont send the form when I do that <?php $number= $_POST['number_entered']; $submitbutton= $_POST['submit']; $randomnumber= mt_rand(1,5); ?> <?php echo ' <form id="id" action="" method="POST"> Guess a Number Between 1 and 5: <input type="text" name="number_entered" value=""/> <br><br> '; echo ' <br><br> <input type="submit" name="submit" value="Enter Guess" /><br><br> </form> '; if ($submitbutton){ if (($number > 0) && ($number <6)){ if ($number != $randomnumber) { echo "Incorrect guess. The correct number was $randomnumber. <a href='play.php'>TRY AGAIN</a>"; } else { echo "$randomnumber is the correct guess. <a href='Some Link To Redeem'>Click Here To Redeem Winning Tokens</a>"; } } } ?>
  10. I like this approach. I could even have it so when they click the redemption, then it enters a "claimed" in the database, and then the page can check for that. So that brings me to a different issue then. | Lets say user "bob" played the game, won the game, and redeemed the prize. Then Bob wants to play again... I would either have to create multiple win pages manually OR make it clear the "claimed" entry to start again. The latter would make more sense and would be easy enough to do. But that would also make it so multiple people could just get the final link to the prize and redeem it You did put me in the right direction. Thank you @Barand I have a starting point now Edit: I think... THINK... also maybe have an entry in the database that matches the users ID to per-say a column names "status" and that can have the value entered in it when the user begins the game that says "Started" and then would allow them to finishe the game, and also a secondary that says "completed". If those values are blank, then the redemption page can check to see for them, and redirect if they are blank.. What are your thoughts on that?
  11. Hello I am looking to create a game that has a link generated upon winning. The game itself is already done so I wont bother you with all of that. The road block that I'm facing is looking for the right direction on making it so the winner get a link to a page where the redemption can be claimed. To give more insight... There is a page I made where a user can click on a button to add 5 tokens to their account That part is also already made and works So when the user wins the game, I want it to be so they can only use the link to that page one time, so that they can't share it with others to give away free tokens, or keep going back to claim more after one win. Is this possible to do without emailing them a link? The website is very strict about not using email. But there are already user logins and such. Edit: I should also say that I haven't tried anything yet because all of my searches are for either sending an email or how to generate a new link token manually so I don't know exactly what I need to do. This has to be generated automatically.
  12. Just to share, I found a completely different set up that works. This follows the rules that Requinix said, but structured different. <script> function myFunction(el) { var hidden = el.previousElementSibling; hidden.style.display = 'block'; hidden.select(); hidden.setSelectionRange(0, 99999) document.execCommand("copy"); hidden.style.display = 'none'; } </script> <input type='text' style='display:none;' value='NOW PLAYING: " . $row["movie"] . " - Requested By - " . $row["name"] . " - Link: " . $row["link"] . "'> <button onclick='myFunction(this)' >Copy</button>
  13. @requinix Thank you so much for taking the time to make that post. I couldn't get that to actually work at all. Nothing gets copied to the clipboard. And thank you for the link for the clipboard API but I'm lightyears away from being able to read that and know how to make a script out of it. I appreciate it though.
  14. Hello. I have the following that works great for the first database entry, but if there is more than one the copy button doesn't copy anything for entry 2, 3, 4, 5, etc. I suspect this has to do with an id issue. But I don't know how to resolve it. Any help is appreciated a lot. Note: I got this from a search in google, so I did not create this. I'm also not including any of the info about the database and such because there's no issues with it. My only issue is the copy button only copying the first in the list to the windows clipboard Here is a shot of what is displayed on the page Here is the script I am using ////// this is what displays the information. It will show in a list on the page each entry in a row and the copy button under each one ////// ////// Each is pulling successfully to display from the database ie movie, name, and link ////// <div id='goodContent'>NOW PLAYING: " . $row["movie"] . " - Requested By - " . $row["name"] . " - Link: " . $row["link"] . "</div> <button id='clickCopy'>Copy</button> ////// this is the javascript to make the function happen - there are extra elements in it that are not being used because this was created as a way to copy different lines, however I just need one line copied ////// <script> copyToClipboard(document.getElementById("content")); document.getElementById("clickCopy").onclick = function() { copyToClipboard(document.getElementById("goodContent")); } document.getElementById("clickCopyString").onclick = function() { copyToClipboard("This is a variable string"); } /** * This will copy the innerHTML of an element to the clipboard * @param element reference OR string */ function copyToClipboard(e) { var tempItem = document.createElement('input'); tempItem.setAttribute('type','text'); tempItem.setAttribute('display','none'); let content = e; if (e instanceof HTMLElement) { content = e.innerHTML; } tempItem.setAttribute('value',content); document.body.appendChild(tempItem); tempItem.select(); document.execCommand('Copy'); tempItem.parentElement.removeChild(tempItem); } </script>
  15. Yes, thats why I said thanks for taking the time and it lead me to go this route. If you didn't help me to what had me not be able to use exactly that, then I wouldn't have thought about using this method. I didn't ignore anything. I tried your method and it failed. This method that I used works. Problem solved. I was trying to give you a positive shout out for helping me lead to that resolution that I like. Edit: This was tested on 10 people submitting at the same time and it worked fine. All it was intended for was to check duplicate entries for a link and then kick back if someone beat them to it. It works flawlessly
  16. For anyone that comes here to see if there is a solution, this is how I ended up going about it. It's not quite the resolution to fit exactly what to fix in the original question but it's a work-around that works perfectly. And thanks to @Barand for taking the time to help, as it lead me to go this route and learn something new. I added this at the top of the php page to check for the duplicate first and if no duplicate then it carries out the rest of the page (that does the instert, bla bla bla stuff). And yes I know the font tags are frowned on but it works and it's an old habbit haha. Also, I had to remove the unique key in the database to make it work as well. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $servername = "removed for posting"; $database = "removed for posting"; $username = "removed for posting"; $password = "removed for posting"; // Start the session session_start(); // Create connection $conn = mysqli_connect($servername, $username, $password, $database); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo " "; $link1 = $_POST['link']; $link = mysqli_real_escape_string($conn , $link1); $dupesql = mysqli_query($conn,"SELECT * FROM nametable where link = '$link'"); if(!mysqli_num_rows($dupesql)<=0){ echo '<center><br><br><br><br><font color="#FFFFFF" size="7" face="Verdana, Arial, Helvetica, sans-serif"><b>Sorry!</b></font><br><br><br><br><font color="#FFFFFF" size="6" face="Verdana, Arial, Helvetica, sans-serif">This link<br>has already been entered.<br><br>Please choose a link</font></center>'; }else{
  17. I thought I'd make a page to check if it's already entered in database 2, and if it is then it shows an error image. But if it's not a duplicate then it redirects to the original page as normal. So I'm hunting a solution for that as it may be the easiest route to go. Something like Page 1 Gets the form and checks if the link being sent is a duplicate. If it is then it goes to page 2. If it's not a duplicate then it goes to page 3 Page 2 Shows a custom message or image to show that the link has already been submitted Page 3 Inserts the link into the database because in page 1, it was not a duplicate link being submitted Cross your fingers I don't lose the rest of my hair trying to make this happen haha. Thank you for your efforts @Barand
  18. No there are over 30 databases on the server. But there are three that being used for this purpose. Also, they all have the same table name and password to connect, but not all the user names are the same
  19. Yes they are all on the same hosting. Just 3 different databases. And sorry, I thought this line was the insert $sql = "INSERT INTO nametable (link) VALUES ('$link')";
  20. Okay so I managed to make it work for just one database (see the code I edited that you gave below). I thought this logic would prevent it from continuing at all for the other 2 but that isn't happening. Reason I have 3 databases for this 1 is the main one where my assistant removes them as they are being used 2 is the backup for one day which is what I'm using for this, so that a duplicate isn't sent for the whole day 3 is for a counter and backup database for all entries What I need this to do is to prevent the duplicate being sent to all of them if the one in the 2nd database has the duplicate (which is the one I set the LINK column to unique) I thought about setting the "link" column to unique on all three but that wouldn't do any good since the 1 and 3 databases get entries deleted constantly so there would be little chance of there being a duplicate. So... another words, I need this to prevent entering at all for any of them, if the database (2) as the duplicate in it. Here is what I have now NOTE: Thank you for all your time with this. I very much appreciate it // show all errors error_reporting(E_ALL); ini_set('display_errors', '1'); // Start the session session_start(); // database 1 $servername = "removed for posting"; $database = "removed for posting"; $username = "removed for posting"; $password = "removed for posting"; // database 2 $servernameS = "removed for posting"; $databaseS = "removed for posting"; $usernameS = "removed for posting"; $passwordS = "removed for posting"; // database 3 $servernameD = "removed for posting"; $databaseD = "removed for posting"; $usernameD = "removed for posting"; $passwordD = "removed for posting"; // Create connection mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect($servername, $username, $password, $database); $connS = mysqli_connect($servernameS, $usernameS, $passwordS, $databaseS); $connD = mysqli_connect($servernameD, $usernameD, $passwordD, $databaseD); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } if (!$connS) { die("Connection failed: " . mysqli_connect_error()); } if (!$connD) { die("Connection failed: " . mysqli_connect_error()); } echo " "; // what is posting from the form $link1 = $_POST['link']; $link = mysqli_real_escape_string($conn , $link1); // enter into database if no duplicate from db 2 // this should add to all three databases if no duplicate but if there is a duplicate in database 2 then it still sends to the other 2 databases try { $sql = "INSERT INTO nametable (link) VALUES ('$link')"; } catch (mysqli_sql_exception $e) { if ($e->getCode() == 1062) { echo "Sorry this was already put in tonight"; } else { throw $e;// in case it's any other error } } // close all connections mysqli_close($conn); mysqli_close($connS); mysqli_close($connD); } ?>
  21. Thank you very much. I have below my edit and I followed your other instructions but I obviously did something wrong with it. Now I just get a blank page. Here is what I have along with editing the db connection and removing the error code try { $sql = "INSERT INTO nametable (link) VALUES ('$link')"; } catch (exception) { if (exception error code is 1062) { // error detected - was it a duplicate? echo "Sorry this was already sent"; // yes it was so report it } else { throw (exception) // no it wasn't so let php handle the exception } }
  22. Please forgive me but where am I putting that in? Or replacing? Do I just add that in and not change what I have but add it before the "insert into...." part?
  23. Hello everyone. After a lot of research, I figured out how to prevent duplicate entries into the database by making the column to check as Unique (column name is link) This works and gives an error, and prevents the entry to be sent to the database, unless it's a unique entry then it will submit. So everything works. I just want to change the error to something else What I can't figure out, is how to change that error to a custom message, or even BETTER a custom image I made Example "You already submitted that link" or show "nono.jpg" This is the error code that shows now (which is doing what it's supposed to, but I want to change it) and this is the script starting at that line if (mysqli_query($connS, $sql)) { echo " "; } else { echo "Error: " . $sql . "<br>" . mysqli_error($connS); } And here is the connS info (note: It's put as "S" because there is more than one connection in the full script, but that isn't a factor in this post because all works perfectly, I just need to change the error code) error_reporting(E_ALL); ini_set('display_errors', '1'); // Start the session session_start(); $servernameS = "Deleted for posting"; $databaseS = "Deleted for posting"; $usernameS = "Deleted for posting"; $passwordS = "Deleted for posting"; // Create connection $connS = mysqli_connect($servernameS, $usernameS, $passwordS, $databaseS); // Check connection if (!$connS) { die("Connection failed: " . mysqli_connect_error()); } echo " "; $link1 = $_POST['link']; $link = mysqli_real_escape_string($conn , $link1); /// Etc etc etc more code and stuff below this, deleted for posting EDIT: I did try this but it didn't work if (mysqli_query($connS, $sql)) { echo " "; } else { echo "That link has already been sent"; }
  24. Thank you. Yes there was a space in it that was bad. Now I'm getting issues with having the include_once script that has always been there for some reason. When I take out the top line that is in the post, there is no issues. But thats a different problem. You're solution worked for the error I was getting. Thank you!
  25. Hello everyone. I got this script from a friend that told me he got it somewhere online so he doesn't know how to fix it. This is a script to ban users if an IP address is listed in a database. That part works. If the IP address is added to the database, then the visitor sees "Access denied!" However, if someone ISN'T listed (their ip address I mean) then the page just says "Uncaught Error: Undefined constant "�" home-iptest.php on line 1" which is the code <?php require_once('ip/ip-access.php'); ?> However, if the ip address is listed in the database then it successfully gives them the access denied test on the page I see in the script there is a place to put the allow access logic, however I don't know what logic or code to put there. Any assistance is appreciated. Here is that script <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $servername = "Removed for posting"; $username = "Removed for posting"; $password = "Removed for posting"; $dbname = "Removed for posting"; // Get the user's IP address $userIP = $_SERVER['REMOTE_ADDR']; // Create a database connection $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Check if the user's IP exists in the database $checkQuery = "SELECT * FROM ip WHERE ip = '$userIP'"; $result = $conn->query($checkQuery); if ($result->num_rows > 0) { // User's IP exists in the database, deny access echo "Access denied!"; // You may redirect to an error page or perform other actions here exit; // Stop further execution of the page } $conn->close(); // If the user's IP does not exist in the database, allow access to the webpage // Your webpage logic goes here ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.