Jump to content

PNewCode

Members
  • Posts

    331
  • Joined

  • Last visited

Everything posted by PNewCode

  1. @cyberRobot You almost got it. Except with that, it's showing a blank background if the column isn't blank instead of what is entered in the db column EDIT... CYBERROOT YOU DID IT!!! I forgot to put the root back in the path when I used yours (I deleted it for posting in here).... YOU NAILED IT THANK YOU!!! For my education, can you please tell me the difference of what I had and what you did so I understand it? MANY THANKS!!!
  2. Maybe this will help The background of the page is getting called from the PHP. Below is that code and the results. Notice that user 2 has no background. It should be using "nouserback.jpg" however if there is one entered, as you can see it works <style> body { background-image: url('<?= $imagePageURL; ?>'); background-position: center center; background-repeat: no-repeat; background-attachment: fixed; background-size: cover; background-color: #000000; } </style>
  3. @cyberRobot Thats what this script should be doing, right? Or am I missing some code somewhere? if (!empty($pageimg)) { $imagePageURL = 'nouserback.jpg'; } else{ $imagePageURL = '/img/'.$row["pageimg"]; }
  4. @cyberRobot Yes exactly
  5. @kickenThats not the part that doesn't work. If there is something in the pageimg row like in the screen shot, then it appears in the page. It's definition is in the part of the script that I'm having trouble with. The part that isn't working, is if it's blank. But it works if something is in that column of the database. Below is the script that defines and uses it. if (!empty($pageimg)) { $imagePageURL = 'nouserback.jpg'; } else{ $imagePageURL = '/img/'.$row["pageimg"]; }
  6. Here is a mock image of the database. User 2 should have the nouserback.jpg showing on the page because it is blank (empty) in the database
  7. @ginerjm Yes turned on and no errors. Also, I did try a different image. It's going to the else image url for each time. Also checked the URL of the image on it's own and it's good @cyberRobot yes it's intentional. One is looking to see if the row is empty. The other is using the row for the file name the column (pageimg) is NULL in the database. Could that be the issue? I DID change it to Not Null once but that didn't make a difference so I put it back to Null
  8. @ginerjm I tried the following (code added below) and what happens is that everyone has "nouserback.jpg" as a background, regardless if they uploaded an image or not (when they upload an image, then the file name gets entered in the column "pageimg". For some reason this is going to the else statement if there is an image file name in that column or not So another words Jane uploads an image, and her image is showing john does not upload an image so the image file named "nouserback.jpg" should be showing. But it doesn't if (!empty($pageimg)) { $imagePageURL = 'img/'.$row["pageimg"]; } else{ $imagePageURL = 'img/nouserback.jpg'; }
  9. Hello all. I think this one will be very simple for most of you (if not all) but yet I'm missing something here and I can't tell what it is. Any insight will be great as I am ready to wave the white flag on this. I have tried switching the if and else and that didn't work. I tried to make it an echo statement to test and that didn't work. PROBLEM: No matter what I put in the IF first part, it gets ignored and just moves to the ELSE statement. The column "pageimg" in the database is set to NULL, however I tried to make it not null to see if that made a difference and I got the same bad results. Goal: If the user has an image title in the database column "pageimg" (ex: myimage.jpg) then the background will show that (this part works) if database column "pageimg" is blank (no entry at all) then it SHOULD show "nouserback.jpg" as the image (this does not work) Any thoughts? NOTE: I didn't include below the connection and stuff because that is working fine to get the image and the other functions of the page. This is the only part that is messing with me (below) Example of what is happening now... User "Jane" uploads an image for her profile background. Jane now has the background image showing ("pageimg") User "John" doesn't upload an image for his background. John has a blank white background instead of showing the image "nouserback.jpg" .... john should have "nouserback.jpg" as a background if (!empty($pageimg)) { $imagePageURL = 'img/nouserback.jpg'; } else{ $imagePageURL = 'img/'.$row["pageimg"]; }
  10. @kicken is that not the JS? I thought I was starting to understand but now I'm just confused. Maybe I need more coffee haha
  11. @cyberRobot and @kicken No errors now but it's also not copying anything to the clipboard. Not even the first one now. I think I missed something between both of your posts. I really do appreciate everything. Here is the full page, maybe it can shed more light. <?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"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM copypaste"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { ; echo " <div> <div class='copy-content'>".nl2br($row['info'])."</div> <br> <a href='updatecopypaste.php?id={$row['id']}'><img src='/ppreq/editbtn.jpg'></a> &nbsp &nbsp <a class='leftf' href='deletecopypaste.php?id={$row['id']}'><img src='/ppreq/deletebtn.jpg'></a> &nbsp &nbsp <button name='copy-button' class='unstyled-button' style='cursor:pointer'><img src='/ppreq/copybtn.jpg' border='0'></button> </div> <br><br>"; } } else { echo "0 Listings"; } ?> <script> window.addEventListener('DOMContentLoaded',()=>{ //Find all the copy buttons document.querySelectorAll('button[name="copy-button"]').forEach((button)=>{ //Add a click handler to each of the buttons button.addEventListener('click', (e)=>{ //Locate the copy-content element const copyContent = button.parentElement.querySelector('.copy-content'); //Do the copy copyToClipboard(copyContent); }); }); }); </script>
  12. @kicken Thank you for that, and also for explaining it so I can understand. However I tried this just now and it gives me "page isn't working". I ran the whole page through an online debugger but it just showed an unclosed { error Parse error: Unclosed '{' on line 31 does not match ')' in /in/upTHA on line 53 Process exited with code 255. I tried in multiple places to close it but couldn't seem to make it work. Here's the whole pages code in hopes that this explains it better (with your update). Also, I know I have 2 different PHP instances, though it was like that when I got it and I didn't see any reason to mess with it unless I have to since it was semi-working for at least the first entry before. <?php $servername = "removed for posting"; $username = "removed for posting"; $password = "removed for posting"; $dbname = "removed for posting"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM copypaste"; $result = $conn->query($sql); $resultt = mysqli_query($conn, "select COUNT(id) AS count FROM `copypaste`"); if(!$result) { die('Error: ' . mysqli_error($link)); } else { $num_rows = mysqli_fetch_assoc($resultt); // echo it echo ""; } if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { ; ?> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); echo " <div> <div class='copy-content'>".nl2br($row['info'])."</div> <br> <a href='updatecopypaste.php?id={$row['id']}'><img src='/ppreq/editbtn.jpg'></a> &nbsp &nbsp <a class='leftf' href='deletecopypaste.php?id={$row['id']}'><img src='/ppreq/deletebtn.jpg'></a> &nbsp &nbsp <button name='copy-button' class='unstyled-button' style='cursor:pointer'><img src='/ppreq/copybtn.jpg' border='0'></button> </div> <br><br>",60); } } else { echo "0 Listings"; } ?>
  13. @mac_gyver Ahhh so it's only capturing the first id then. Any idea on how to add to this to grab the id for that specific entry? As for showing more, I don't have more to show outside of what I posted. I'm sorry I don't understand what you are asking for. My apologies
  14. @ginerjm I want to make it so the javascript to make the "copy button" work for each listing instead of just the first one. See the screen shot below. Right now, if you click on the first entry's copy button, then it copies it to the clipboard and can be pasted somewhere else (in a chat, notepad, etc) If you go to the 2nd entry in the list, the copy button does not copy anything to the clipboard. So this is only working for the first entry. Not the rest of them
  15. @ginerjm I said what the plan is lol. This works for the first entry in the list. It doesn't work for anything after the first entry. Anotherwords, there are several entries in the database. If I click on the copy button for the first one, then it will copy to the clipboard and the user can paste it somewhere else. BUT... if you click on the copy button on the 2nd one, then it does not copy anything to the clipboard. This is only working for the first in the list when displaying all of the entries
  16. Hello. I selected php help because the loop where I need the function is in the php section. What I have is something that ALMOST works. The code below allows for the first value in the list (loop) to be copied to the devices clipboard, but only the first one. (row "info"). I am guessing it's because my javascript isn't in the loop itself. I tried multiple times to move the js into the loop but then it just makes the page blank. I'm not showing examples of what I tried because there's been so many attempts that I don't remember them all. So what I am showing is what works for copying the first entry. Goal is to get this to work with each entry. NOTE: I didin't include any connection to the database because all of that is working just fine and displaying all of the different entries and values. The copy function to work in the loop instead of just the first one is the only issue I'm having. Also, if anyone is wondering why I did "this and that" it's because everything except adding the id and the javascript was already made by someone else. I"m just adding the copy function to this <?php error_reporting(E_ALL); ini_set('display_errors', '1'); echo nl2br( "<div id='goodContent'>" . $row['info'] . "</div><br><a href='updatecopypaste.php?id=" . $row['id'] . "'><img src='/ppreq/editbtn.jpg'></a>&nbsp &nbsp<a class='leftf' href='deletecopypaste.php?id=" . $row['id'] . "'><img src='/ppreq/deletebtn.jpg'></a>&nbsp &nbsp<button name='copy' id='clickCopy' name='copybtn' class='unstyled-button' style='cursor:pointer'><img src='/ppreq/copybtn.jpg' border='0'></button><br><br>___________<br><br>",60); } } else { echo "0 Listings"; } $conn->close(); ?> <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>
  17. Sorry everyone. I had a crash from a diabetic incident and was gone. @AKADRUMMIN nailed it. The fix was `mybandid` = '$mybandid. That resolved it. I'm in shock that I missed something so simple to fix and a little disappointed in myself for not catching that but, hey... this is how we learn right? Thank you so much everyone. Now I know how to make that work and why. I appreciate everyones input sooooo very much!
  18. @Barand yes it does. It's the logged in users id, that is also in the database's table column "mybandid" The user that is logged in, is 281. When that user made the EPK, his user id is put in this table under the column "mybandid". So this way both are with the same id number... in the table "users" and "bandstage"
  19. @mac_gyver thank you much for that effort. I appreciate it. First I tried to translate what you have in comparison with what I did, and also with the other comments to understand it. Then I realized I could not make heads or tails of it because it's more advanced than my understanding. Even a lot of the verbage thats said I don't understand haha. So THEN I thought I would copy and paste it, and if it worked then I could go in and learn to see WHY it worked and then learn and understand it (which is how I learn best unfortunately), but alas it didn't work. Not even adding the error scripting and there was no error displaying. Just a white page. But I thank you for taking the time to write that out to help me
  20. I know, but I removed it so it wouldn't switch to that page in the header statement before I could see the results of the code he had me put in (so it stayed on that page) Same database, different tables. One table is "users" that has all the users that login and their user id's. The other table is "bandstage" that has their EPK's they create
  21. @Barand and @ginerjm this is the echo I'm getting. And that is the correct id DELETE FROM bandstage WHERE id = 281 Yes testing it after logged in too So since it's getting the correct ID, then why in the world isn't it deleting the record for it? @mac_gyver thank you for that education. my amatuer mind understood about half of that but that also gives me some more to look up to learn from.
  22. @ginerjm Thank you. I can't put the id value in because that could be different for each user. So it has to be from whoever is logged in on that page (session id) @Barand I removed the header and added your code, though no error is displaying Any thoughts?
  23. Hello everyone! I hope your day is awesome. I have a puzzling issue. I have made plenty of files that delete records from databases, however those all call for such as "?id=blablabla". This time I'm calling it from a button that grabs the session and is supposed to get the id from that. But it's not deleting the record. Here is the full script. If you want to know where it's coming from, it's just a button on a previous page that links to this page below No errors are displaying on screen nor in the log NOTE: "mybandid" is equal to the user id in the database (but different table called "users"). This is to identify that entry for that specific user from a different table. Which works for displaying the page. so if the user id is 100, then the mybandid is also 100 in this database <?php error_reporting(E_ALL); ini_set('display_errors', '1'); // Start the session session_start(); $servername = "Deleted For Posting"; $username = "Deleted For Posting"; $password = "Deleted For Posting"; $dbname = "Deleted For Posting"; //Connect DB //Create query based on the ID passed from your table //query : delete where id = $mybandid // on success delete : redirect the page to original page using header() method $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // sql to delete a record $mybandid=$_SESSION['id']; $sql = "DELETE FROM bandstage WHERE id = $mybandid"; if (mysqli_query($conn, $sql)) { mysqli_close($conn); header('Location: delete-epk3.php'); exit; } else { echo "Error deleting record"; }?>
  24. @ginerjm I got it. So from what you posted... I started to build up a second query but it was failing. Thats because I was just putting that in with the other one. I see that I had to have a complete new query (forgive my jargon, I haven't learned the right termonology let). So I replicated what I had, and renamed the second one, and put in my UPDATE command instead of the INSERT in the 2nd one. I did get some help on this outside of here to understand to rename it to have a difference. Thank you much for the help I appreciate it. Solution
×
×
  • 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.