Jump to content

PNewCode

Members
  • Posts

    315
  • Joined

  • Last visited

Everything posted by PNewCode

  1. @Barand I see. And yes since I really only need the birthday listing for this I changed it. I am getting "page isn't working" with it now though. I changed up the ' to " just in case (that is normally why I get that) and got the same results. I used the online trouble shooter and got Parse error: syntax error, unexpected identifier "birthday" in /tmp/preview on line 25 (this line 25 was with the db connection stuff typed in so it wont match a line 25 below but it's in the sql=select line) The column name that the birthdays are listed in is named birthday, so I'm not seeing where the problem is. It would be helpful if the error reporting also told why the page "isn't working". I don't have access to the server logs for this one. Any thoughts? <?Php error_reporting(E_ALL); ini_set('display_errors', '1'); //// db connection stuff here, removed for posting //// $conn = new mysqli($hostname, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = SELECT birthday FROM retirees WHERE MONTH(str_to_date(birthday, "%m/%d/%Y")) = MONTH(CURDATE()) AND DAYOFMONTH(str_to_date(birthday, "%m/%d/%Y")) = DAYOFMONTH(CURDATE()); if (!$result = $conn->query($sql)) { die ('There was an error running query[' . $conn->error . ']'); } ?>
  2. @Barand thank you. I will test these out to see if I can get them to work when I get back to the computer in the morning. I appreciate it. From what I'm understanding, since my database is called "retirees" then I would have it like the following, and I choose the * so I can also include their name and favorite birthday cake that is listed. SELECT * FROM retirees WHERE MONTH(str_to_date(birthday, '%m/%d/%Y')) = MONTH(CURDATE()) AND DAYOFMONTH(str_to_date(birthday, '%m/%d/%Y')) = DAYOFMONTH(CURDATE()); and this will look for the birthdays that are on the current date at the time of looking at the webpage, because the string format is being converted and then it's looking for the current date and month, instead of the year too. Correct?
  3. @Barand I see what you mean. Thats great for displaying it in a different format, but I'm not understanding how I can use that to display only the birthdays that are on the day that the page is viewed?
  4. @Barand and @kicken Thank you much. For this one, I don't think it would be wise for me to convert values in the database because it's not mine. I'm only making a Birthday listing from it. If something went wrong, I wouldn't be able to change it back, or have access to import the database again. All I can do with this project is make a display page so I think I better not convert any data in it. I am looking into the LIKE thing now. Thank you for that. I think this will take me some time to figure out how to make it work specifically for what I need but I appreciate the direction. Thank you very much
  5. I have an old database that has dates that are entered from a date picker. I don't have access to that database to change the structure of it because it's from an old partners website that told me "You can use it but I'm not messing with that stuff anymore" and wont give me the login info. (only giving a reason why I can't change that) TASK: To have a php page that selects the listings that are TODAY from the "birthday" column, so I can displays todays birthdays. However the column is VARCHAR instead of DATE I googled this but my googlie gunk only gave me results on a process to change the table structure and convert. Is there a way to select today, from the birthdays that are in today (not todays specific date, but like, tomorrow will be a new "today"... etc) The dates list like the following examples in the column "birthday" 01/15/1980 10/22/1989 11/09/1979 ... etc I'm not asking for anyone to write out a page for me. Just maybe something easier for me to follow than the google results I keep seeing that seems to assume everyone is an expert and can translate everything lol MANY THANKS!!!
  6. Between what @requinix and @kicken posted and gave for references and things to focus on, and what I looked online, this is what I have so far. One pesky thing left is if there is no www or http or https and is, for example google.com side note... once I get this one figured out, I'm going to take on getting the default thumbnails for urls Any thoughts on that last bit? //If it has https// $comment= nl2br(preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $comment)); //if it doesn't have https// $comment= nl2br(preg_replace("#(^|[\n ])((www)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"https://\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $comment)); //Make the email address clickable to mailto stuff// $comment= nl2br(preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $comment)); //To turn the http into https// $comment= str_replace('http://', 'https://', $comment);
  7. @Barand Thank you for changing the title for me. I was trying to correct that haha
  8. @requinix You're right. I have a very backwards way of learning stuff. I suspect that stems from making radios and stuff when I was a kid, and just pairing wires (so to speak) that looked like other working radios till it worked, then I would be able to see why those connections worked. This isn't good practice for this. I'll try to change my habbits The text that is for the link is picked up automatically with this, from within the comment. So for example if the user enters I wanted to get my new shoes on sale but they are only discounted at https://www.shoes.com so I went to the website It would echo on the page I wanted to get my new shoes on sale but they are only discounted at https://www.shoes.com so I went to the website with the website as a link OH... and as I'm typing this, it looks like this forum is doing that too haha. Thats awesome. Okay so now I'm more confused than I thought I was. Where do I add the other options in that? Admittingly, the "https" is the only thing in all of that, that is recognizable to me haha
  9. @requinix No I don't have that in there. This is what I tried (sorry I should have put this in the original post) $comment = nl2br(preg_replace_callback('~(\bhttps|http|www|mailto|.?://\S+)(?:\s+\[([^]]+)\])?~i', and $comment = nl2br(preg_replace_callback('~(\bhttps,http,www,mailto,.?://\S+)(?:\s+\[([^]]+)\])?~i', and $comment = nl2br(preg_replace_callback('~(\bhttps?://\S+)(?:\s+\[([^]]+)\])?~i', $comment = nl2br(preg_replace_callback('~(\bhttp?://\S+)(?:\s+\[([^]]+)\])?~i', $comment = nl2br(preg_replace_callback('~(\bwww?://\S+)(?:\s+\[([^]]+)\])?~i', $comment = nl2br(preg_replace_callback('~(\bmailto?://\S+)(?:\s+\[([^]]+)\])?~i', $comment = nl2br(preg_replace_callback('~(\b.?://\S+)(?:\s+\[([^]]+)\])?~i', But none of those worked
  10. I decided to learn a little bit about preg_replace in strings while I have a couple days of down time from activities away from the computer. I have a table that echo's the results from the mysql value in the column "comments" That works Now I added some code that I had to collect and change a LOT of times to make it work, that shows line breaks, and also converts links in the text to url's that open in a new window. Which is AWESOME! The problem is, I want to have it also work this wizard-like magic for mailto, www, and just something.com For example... What it works on now is any text that is a full written url such as https://www.google.com I also need this to work for, examples (not these specific urls, just whatever is in the text) www.google.com google.com person@gmail.com I came KIND of close, but the ones that were without the https:// in front, just ended up resulting in a link that took them to (for example) https://www.mysite.com/www.google.com So I scrapped all of that because it was making a mess. The code below is what I have that still works with the first part of this post that I have working for a full link I'm excited to see what I learn from this one ///// a bunch of connection to the database stuff here, removed for posting //// $comment = $row["comment"]; $comment = nl2br(preg_replace_callback('~(\bhttps?://\S+)(?:\s+\[([^]]+)\])?~i', function ($m) { $s='<a hr'.'ef="'.$m[1].'" target="_blank">'; $s .= isset($m[2])? $m[2]:$m[1]; return $s.'</a>';}, $comment)); //// echos out below //// <font face="Verdana, Arial, Helvetica, sans-serif" color="#ffffff"><b>'.$comment.'</b></font>
  11. @kicken Thank you! Great education again and now it all works smooth!
  12. @kicken Thank you much. I'm getting a new error now when I added that sayin which is wierd because I didn't get that before I added it, only the error that says I'm using a ' in the string. I added $ppname1 = $_POST['ppname']; $ppname = mysqli_real_escape_string($conn , $ppname1); And that second part, I'd like to circle back to that and get some more education on that
  13. Hello again everyone! Today I'm working with learning file uploads. I faces an issue when uploaded a song that has a special character, for example YA'LL I managed to take care of this for the text field by using $band21 = $_POST['band2']; $band2 = mysqli_real_escape_string($conn , $band21); But I don't see where to add such a thing for the file name of the song upload. Any thoughts? NOTE: This works perfectly as long as there's no special characters in the file name Btw, I know this is a bit messy and amatuer, please keep in mind that I'm still learning <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); CONNECTION STUFF HERE (removed for posting) // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $id=$_SESSION['id']; $sql = "SELECT * FROM users WHERE id=$id"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $band21 = $_POST['band2']; $band2 = mysqli_real_escape_string($conn , $band21); } } else { echo " "; } if (isset($_POST["submit"])) { $allowed_audio = array('mp3','wav'); $audio_ext = $_FILES["file2"]["name"]; $ext2 = pathinfo($audio_ext, PATHINFO_EXTENSION); if (!in_array($ext2, $allowed_audio)) { if (!in_array($ext2, $allowed_audio)) { echo 'Only Mp3 or WAV Files are Allowed to be Uploaded'; } die(); } #file name with a random number so that similar dont get replaced $ppname = rand(1000,10000)."-".$_FILES["file2"]["name"]; #temporary file name to store file $ttname = $_FILES["file2"]["tmp_name"]; #upload directory path $uploads_dir = 'member-audio'; #TO move the uploaded file to specific location move_uploaded_file($ttname, $uploads_dir.'/'.$ppname); $sql = "UPDATE users SET band2 = '".$band2."', audio1 = '".$ppname."' WHERE id = $id"; if(mysqli_query($conn,$sql)){ echo " "; } else{ echo "Error"; } } ?>
  14. EUREKA!!! Just to share, here's the winning solution. I chaged it to <a href="my-profile.php?id='.$myid.'">Your Profile</a> and added $myid = $row["id"]; To the while($row = $result->fetch_assoc()) { Okay so I'm learning so much and I'm really rather excited. Especially when things WORK! lol
  15. I decided to go a different route because to be honest, with the rest of the pages design in html, the drop down menu just looked ugly lol. So I just made it an auto filled form with the id passed to it. HOWEVER, I have a new problem with this. The page also needs to grab the id of the user that is logged in, to ALSO send in part of the form. There is a "vew profile" link like in my previous post. But this one serves as a purpose for the user to view their own profile to see if they want to make any changes. In the top menu, I use once again <a href="my-profile.php?id='.$row['id'].'">Your Profile</a> But the results are my-profile.php?id= What was built on the previous post works because it's sending the id of someone else that is in a table that has many users. This doesn't because I don't seem to understand where to grab the id of the user logged in, instead of the id of someone else. Any thoughts?
  16. Hello. First... WOW I learn so much on here. Today I'm facing a new task I am bringing upon myself to take something I already have, and make it more specific. I have a drop down menu that selects a user name, from a list of users in the database. This works great. However, now that the list is getting longer, I am attempting to have this populate with only one specific user instead of all of them. This is the scenerio I want to achieve I am at the website, and I want to go to "bob"s profile page. When I get there, I see I can send him a gift (or a message). So I click on that button but it sends me to a page where I have to scroll through over 400 names to get to it. So now I am annoyed and leave the website. I wish the developer (hehe) just made it so his name was there. Bob's id in the database is 215 What I have now works great to select a person and move on to the next page and send them something based on the name because it also gets their id. So how can I do this to capture ONLY the id of the page I'm visiting, and have that as the only option in the list? (I can't just have only 215 and bob in the list because this will depend on which page is being visited) Note: Considering that everything works solid with the rest of the page with a full drop down list, and that is the part I want to edit, I am assuming that is all I should show on here to reduce clutter. If I should show more than I apologize and I am willing to post whatever else is needed to be seen <select name="gname" style="font-size:18px;"> <option>Choose A Member</option> <?php $sqli = "SELECT * FROM users ORDER BY fname ASC"; $result = mysqli_query($con, $sqli); while ($row = mysqli_fetch_array($result)) { # code... echo '<option value="'.$row['id'].'">'.$row['fname'].'</option>'; } ?> </select>
  17. @gizmola Thank you very much for the insight and education. I much appreciate it
  18. ARGH!!! Update! I feel so silly now... it was in the WHERE statement. I typed it right in the description but I wasn't typing it right in the actual script. I was putting the "?" in both ends of it. Problem is solved with $sql = "SELECT * FROM users WHERE id = '$id'"; Sorry if I wasted anyones time. Problem solved.
  19. Hello wonderful people! This one has me about pulling my hair out. All my google research and php help topics I can find, tell me that there is nothing wrong with what I have. Though I fully accept that I am clearly doing something wrong, as this is not working. Below is my code (simplified). I didn't include the connection info for obvious reasons. And I didn't include all the pages scripting that just shows pictures and stuff that aren't related to this (just images that are embedded and what-not) The PROBLEM is that when I go to the page (example https://www.website.com/profile.php?id=65) it brings up the profile for the id 218. In fact, I can replace the "65" with ANY number, and it will still bring up the database info for ID 218 Any thoughts on this? Note: The only parts I'm not including in this entire pages script is just the embedded pictures and still stuff that I typed on the page to read, which has no functions at all Note 2: If I change the SELECT line to $sql = "SELECT * FROM users WHERE id = '$user_id' "; OR $sql = "SELECT * FROM users WHERE id = '$id' "; Then I just get "0 Results" writen on the page Note 3: Keep in mind that ALL of the data shows on the page. The problem is that it is getting id 218 instead of what I put in the url. <?php session_start(); $hostname="localhost"; $username="Removed for posting"; $password="Removed for posting"; $dbname="Removed for posting"; $conn = mysqli_connect($hostname, $username, $password, $dbname); if(!$conn){ echo "Database connection error".mysqli_connect_error(); } $id=$_GET['id']; $sql = "SELECT * FROM users"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $user_token = $row["token"]; $fname = $row["fname"]; $email = $row["email"]; $unique_id = $row["unique_id"]; $facebook = $row["facebook"]; $instagram = $row["instagram"]; $twitter = $row["twitter"]; $youtube = $row["youtube"]; $tiktok = $row["tiktok"]; $osite = $row["osite"]; $favmovie = $row["favmovie"]; $favactors = $row["favactors"]; $favbands = $row["favbands"]; $favseason = $row["favseason"]; $birthday = $row["birthday"]; $locationn = $row["locationn"]; $sign = $row["sign"]; $imageURL = '/chat-v3/public/storage/images/'.$row["img"]; $bio = $row["bio"]; } } else { echo "0 results"; die(); } ?> ////// A bunch of pictures and stuff here within html that show up just fine //// <font face="Verdana, Arial, Helvetica, sans-serif"><b>User Info</b></font> <font face="Verdana, Arial, Helvetica, sans-serif"><b><?php echo $fname; ?></b></font> // The line above repeats to show the rest of the values in the database
  20. @ginerjm and @jodunno thank you both. I haven't got to do any more with this task yet because I had to go spend some quality time with the doctor for a day but I will return to it soon And yes I look forward to learning more CSS, thank you for that example. I'll use that to mold more like it and learn from it.
  21. Hello everyone My next learning adventure is almost complete, except for a pesky issue with refresh. So, the page refresh is necessary because it displays data from my database in real time Note: I know that ajax is better for this however that method still used a fresh, or at least the way I could make it work did. So since this is easier for me to learn from now (baby steps for my mind) I'm going with a script to refresh the page The problem... the page that I have that is being refreshed is in an iframe (because it has to be within a page with other link options to it, bla bla bla) and in that iframe, has a page that has a popup modal (which is important because the main page with content will still have to be behind it) If the button is clicked to bring up that popup, then it opens for 1 second (the time of the refresh) and then disappears I understand why this is happening. So what I want to know is, is there a script or something that can pause the refresh while the popup modal is open, OR have the modal open on TOP of the iframe, and still keep the database info that is within the page, inside that iframe? Note: The modal works perfect on the page when viewing Outside of the iframe, but that is because there is no refresh on it by itself. Only the iframe is being refreshed I'm guessing the option to pause the refresh might be best. Here is the refresh that is in my main page <script type="text/javascript"> setInterval(function(){ $('#test').load('batch.php'); },1000); </script> And here is the modal inside "batch.php" // one or more of these might be for something else on the page. I lost track to be honest which one is for the modal <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <script> function show_modal(e) { console.log (e.href); $("#iframe_modal").attr("src", e.href); $('#myModal').modal('show'); return false; } </script> // below is what is inside the modal which is a form to send info to the database <table width="40%" border="0" align="center"> <tr align="center" valign="middle"> <td> <div class="container"> <br> <a href="post-req.php" class="btn btn-primary" onclick="return show_modal(this);">Comment</a> <br> <br> </div> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Comment This</h4> </div> <div class="modal-body"> <iframe id="iframe_modal" src="" style="width: 100%; height: 40%;"></iframe> </div> <div class="modal-footer"> <button type="button" class="btn2 btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </td> </tr> </table>
  22. @Barand and @ginerjm Thank you. This cleared up what I was stuck on. Awesome sauce is what you all are!
  23. Hello everyone! First, I must say that what I've been able to accomplish in the last few months from learning on here and research has given me a LOT of fun, which is what I need with my old bored self haha. So thank you all! For my next learning experience, I am attempting to display 2 different "things" from 2 different databases. One is a text and one is an image. I should let you know, that this is not an actual project. I'm doing this just for learning because I thought "hmmm, what if I did this..." So no luck. Below is what I tried. Any thoughts? (and before anyone asks, I did it this way because this was my best attempt. I am still figuring out the ways of the php magic ) <?php // Database 1 $hostname = "localhost"; $username = "stuff"; $password = "stuff"; $dbname = "stuff"; // Database 2 $hostnameB = "localhost"; $usernameB = "stuff"; $passwordB = "stuff"; $dbnameB = "stuff"; // Both databases have the same table name $conn = mysqli_connect($hostname, $username, $password, $dbname); if(!$conn){ echo "Database connection error".mysqli_connect_error(); } $connB = mysqli_connect($hostnameB, $usernameB, $passwordB, $dbnameB); if(!$connB){ echo "Database connection error".mysqli_connect_error(); } $sql = "SELECT * FROM tablename"; $sqlB = "SELECT * FROM tablename"; $result = $conn->query($sql); $resultB = $connB->query($sqlB); if ($result->num_rows > 0){ // output data of each row while($row = $result->fetch_assoc()) { $comment = $row["comment"]; } } if ($resultB->num_rows > 0){ // output data of each row while($row = $resultB->fetch_assoc()) { $imglink = "img/".$row['img']; echo' <table width="10%" border="0" cellspacing="0" cellpadding="10" align="center"> <tr align="center"> <td valign="middle"><img src="'.$imglink.'" width="50" height="50" /></td> <td valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" color="#CCCCFF"><b>'.$row["comment"].'</b></font></td> </tr> </table> '; } } else { echo "0 results"; } ?>
  24. @kicken I added the exit; because I know you are all much wiser than me for this. But I also wanted to share with you, that I just added all this to work as an admin page on my other site and it works the same. Even without the exit at the end, it still does as it's supposed to. If you go directly to the url, it just spits them back to the other page if they don't have the "yes" for that value in the database column. I made a test account that doesn't have that credential and one with it. And it does as it should. Without that credential that is auto detected, they can't see the page and are redirect to a "nono.php" page. However, I put the exit back on anyways just to stay with what I'm learning here, but I see no difference in the function when using the page. Just wanted to share that with you
×
×
  • 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.