Jump to content

PNewCode

Members
  • Posts

    331
  • Joined

  • Last visited

Everything posted by PNewCode

  1. @mac_gyver and @Barand thank you for that info! I appreciate it. I think I understand what you're saying. But then again not really haha. If I'm understanding you, then it's not really working to post anything but is just recycling the page to make a new math problem? But then, it's not? Just translating in my own mind that is less skilled with less termonology haha. Okay so, is what I'm attempting to accomplish even possible then to do all in one page? The only session that I have with it is the users session (different php script that is going to be included once I get this working so I can add some database scores and etc etc)
  2. Hello everyone. I hope you're having a great day! I'm attempting to make a basic math test that gives one question, a input field to enter an answer, and if its correct then it shows the answer and an image to say they win. If in correct then still shows the answer with an image that says they didn't win. Sounds pretty basic right? I can't wrap my head around what I'm doing wrong. When I run this, then weather it's right or wrong, I just get a blank page. I've been at this for so long with different variations that I'm starting to feel fatigue haha. Any help is greatly appreciated. The file is math8.php PS I also get the follow errors which is confusing me because in my mind, these ARE defined. But I can see that the errors say their not. I'm not understanding why though. Warning: Undefined array key "number_entered" in math8.php on line 32 Warning: Undefined array key "submit" in math8.php on line 34 <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $rand1 = rand(0, 9); $rand2 = rand(0, 9); $operator = array('*', '/', '+', '-'); $randoperator = $operator[rand(0, 3)]; switch ($randoperator) { case "+": $finaalvalue = $rand1 + $rand2; break; case "-": $finaalvalue = $rand1 - $rand2; break; case "*": $finaalvalue = $rand1 * $rand2; break; case "/": $finaalvalue = $rand1 / $rand2; break; echo $rand1 . $randoperator . $rand2 . '=' . $finaalvalue; } ; if(!isset($_POST['number_entered'])){ $number= $_POST['number_entered']; $submitbutton= $_POST['submit']; echo ' <form id="id" action="" method="POST"> <br><b>Level 1<br>Do The Math</b><br><br>'; echo $rand1 . $randoperator . $rand2 . '='; echo '<input type="text" name="number_entered" value="" autocomplete="off"> <br><br>'; echo ' <input class="button" type="submit" name="submit" value="Enter Guess"><br><br> </form> '; if ($submitbutton){ if ($number != $finaalvalue){ echo "Incorrect guess<br>The correct<br>number was <b>$finaalvalue</b> <br><img src='sorry-tryagain.png'><br>"; }else{ echo "<img src='you-win.png'><br><b>$finaalvalue</b> IS THE<br>CORRECT GUESS!</b><br>"; } } } ?>
  3. Update... For anyone that comes here to find an answer, I was making some coffee and it hit me... I should define the first part, then make it a full url to strip the video id, and THEN put it in the rest to get the title. And after about 20 min of mangling it, this is the solution that works $ytvideo1 = $link; $linkurl = "$ytvideo1"; parse_str( parse_url( $linkurl, PHP_URL_QUERY ), $vid ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $linkurl, $match); $youtube_id = $match[1]; $preurl = "https://www.youtube.com/watch?v=$match[1]"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $preurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $document = htmlspecialchars($output); curl_close($ch); $line = explode("\n", $document); $judul = ""; foreach($line as $strline){ preg_match('/\&lt;title\&gt;(.*?)\&lt;\/title\&gt;/s', $strline, $hasil); if (!isset($hasil[0]) || $hasil[0] == "") continue; $title = str_replace(array("&lt;title&gt;", "&lt;/title&gt;"), "", $hasil[0]); } echo $title; ////// This shows the title of the video from any youtube link
  4. I saw those pages. Good tools I'm sure to use. I was hoping to try to make this work as I'm working on it though. Mainly because if I use their api and then run into this later for something else that needs regex, and there is no api for it (other than youtube for example) then I will be back to this step trying to make it work again. Most of what I do (this is mostly as a hobby, sometimes as a favor for friends) is to build, then learn from it. Even when I get clips of code from other sites, I'll often be able to see why it works, once it finally does work. Not so much the case with redex though. It's really tough to transate for me
  5. That would be a doable except unfortunately all of that string of things looks like a plate of spaghetti trying to be alphabet soup haha. I can't translate it enough to know how to add the "title" part to a different one, or how to make the current one for the title work with youtu.be Also, there's the other issue when the "?si=" is added from the token shared link. I managed to make it all work for the thumbnail, but not the title. And honestly, that was done by stumbling upon the code on other sites. I continue to look into the regex101 and other sites but my brain doesn't want to translate how to break apart all that string of stuff to understand it, to build onto it.
  6. I'm attempting another go at this regex world and I feel like I'm reading something from mars. So I have 2 different codes that work for 2 different things. I'm hoping I can get some help with merging them. I stared at the regex101 for a few days now and I'm not getting it. Note: I didn't include any database stuff or connections and etc. I don't think it's relevant because the link is being sent just fine. I can't get it to convert. Objecting: To sort of "Smush" the two regex together to be able to get the title from any youtube link type. This one works for getting the title of a youtube video, if the video link is (for example) https://www.youtube.com/watch?v=HQBG42Ggtac However it will NOT work with videos withe a link like https://youtu.be/HQBG42Ggtac?si=l2EE-4vqC9U5xIkj <?php $link = $_POST['link']; ////// coming in from a form on a webpage as the user enters a youtube link $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $document = htmlspecialchars($output); curl_close($ch); $line = explode("\n", $document); $judul = ""; foreach($line as $strline){ preg_match('/\&lt;title\&gt;(.*?)\&lt;\/title\&gt;/s', $strline, $hasil); if (!isset($hasil[0]) || $hasil[0] == "") continue; $title = str_replace(array("&lt;title&gt;", "&lt;/title&gt;"), "", $hasil[0]); echo $title; ////// prints the video title on the screen ?> HOWEVER... The following will work when getting ALL links for getting the video thumbnail $link1 = $_POST['link']; ////// sent from a form on a different page $ytvideo1 = $row['link']; $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]; echo "<img src='http://i4.ytimg.com/vi/$match[1]/mqdefault.jpg'>"; ////// shows the video thumbnail Any guidance is massive appreciated. My few remaining hairs will thank you too as I wont pull the rest of them out trying to get this to work haha.
  7. Update. Here is the working final if anyone else comes here looking for a solution. I credit @Barand for getting me there! ❤️ $sql = "SELECT SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) >= 6) as expired , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) >= 3 and timestampdiff(MONTH, created_at, now()) < 6)as warning , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) < 3) as pending , SUM(visited IS NOT NULL) as ok, visited, created_at FROM users ORDER BY visited DESC";
  8. Hello again. I went with this one after adding a few other lines after it to print it out correctly and this works. However I changed it to the following and it's echo $sql = "SELECT SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) >= 6) as expired // after 6 months it is expired , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) > 3 < 6) as warning // between 3 and 6 months it is in warning , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) < 3) as pending // after 3 months it is pending , SUM(visited IS NOT NULL) as ok, visited, created_at FROM users ORDER BY visited DESC"; $query_result = $conn->query($sql); while ($row = $query_result->fetch_assoc()) { $visited = $row['visited'] ; $created_at = $row['created_at'] ; } $result = $conn->query($sql); if(!$result) { die('Error: ' . mysqli_error($link)); } else { $num_rows = mysqli_fetch_assoc($result); // echo it echo "<font color='black'>Expired</font>: <font color='red'>" . $num_rows['expired']."</font>"; echo "<br>"; echo "<font color='black'>Warning</font>: <font color='red'>" . $num_rows['warning']."</font>"; echo "<br>"; echo "<font color='black'>Pending</font>: <font color='red'>" . $num_rows['pending']."</font>"; echo "<br>"; echo "<font color='black'>Okay</font>: <font color='red'>" . $num_rows['ok']."</font><br><br>"; } I know my font tags aren't exactly ideal. I get told that a lot. But since they still work and it's what I'm used to, I don't put it as top priority to change yet lol THE PROBLEM is this is what it prints Expired: 186 Warning: 321 Pending: 44 Okay: 28 And there are only 349 records. So I'm assuming something is wrong with the Expired and Warning because the Okay and Pending are accurate Here's something I didn't explain before and I should have... and I apologize for that. So a lot of those accounts don't have ANY login entry at all, and it is blank in the "visited" row What I am attempting to do is * if the user has logged in (visited has a timestamp), and is less than 3 months since they logged in, then it's in Okay * if the user made the account, and hasn't logged in since they created it (visited column is still blank) in less than 3 months, then it's in Pending * if the user has logged in (visited has a timestamp), and hasn't logged in more than 3 months but less than 6 months, then it's in Warning * if the user made the account, and hasn't logged in since they created it (visited column is still blank) in more than 3 months but less than 6 months, then it's in Warning * if the user has logged in (visited has a timestamp), and hasn't logged in more than 6 months, then it's in Expired * if the user made the account, and hasn't logged in since they last logged (visited column is still blank) in more than 6 months, then it's in Expired Somehow, what you provided ALMOST works. But that Expired and Warning is off some how. Any thoughts? Side note: I didn't attempt your last suggestion because (thought I could be wrong) it looks like I would have to alter the database and I'm not allowed to do that. But good educational suggestion still
  9. @Barand You're awesome thank you. I can't wait to test all of that out tomorrow
  10. Thank you I will certainly give that a shot tomorrow when I get back to the computer. Just for educational purposes though, is it not possible to stem from what I had and add to it? Like for example if ($diffdate->m >= 3 OR $diffdate->y >= 1) { $total1 = (something here that counts the above if statment for a total with that condition); } echo $total1; If not, I'd be curious to know why? Many thanks!
  11. Oh I'm sorry. It's update.
  12. Yes each time they login, a new date enters in "visited"
  13. $sql = "SELECT id,unique_id,fname,date_format(visited, '%b %e %Y %h:%i%p'),date_format(created_at, '%b %e %Y %h:%i%p'),visited,created_at FROM users ORDER BY visited DESC"; This is important to have as a ORDER BY because the list as a whole starts with users most recent logged in to last
  14. The database table has colums "created_at" and "Visited" The code above shows each one correctly as exired = hasn't logged in at all since they created the account and it's been over a year and 3 months pending = hasn't logged in at all since they created the account and it's been within 3 months since created okay = has logged in within 3 months since last login Created_at = created account Logged in = visited So I want to use that information to count (the code in the original post shows each one) how many are Expired how many are Pending and now many are Okay
  15. Hello. I have a few pages that count total entries in a db that work fine. And I have some that count entries WHERE just fine. But what I'm not able to figure out is how to echo a count based on a few variables that are stated after the initial SQL statement. I want to be able to have (for example) echo = 'Okay = 10, Pending = 5, Expired = 2'; and it based on if ($diffdate->m >= 3 OR $diffdate->y >= 1) { $expire = "EXPIRED"; } elseif (empty($visited)) { $expire = "PENDING"; } else { $expire = "OKAY"; } Any thoughts?
  16. @Barand Thank you! You've been a huge help!!!
  17. @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"
  18. 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')";
  19. 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
  20. 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
  21. I found somewhere that someone used si=([\w_]*) so I tried to add that in what I have but zero luck with it.
  22. @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
  23. 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.
  24. The second part of my question I resolved using if(!isset($_POST['number_entered'])){
  25. @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>"; } } } ?>
×
×
  • 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.