Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About JonnyDriller

  • Rank
  1. Thanks guys for the great advise. When all this is over and done, I'm gonna revisit web development on a nice platform, with a proper text editor... i.e not a Raspberry pi that existed 2 decades ago This IOT project is gonna sit on a localhost...yeh I know... So it doesn't have to be super secure. I'm gonna do a screen recording of it and then I'm going to trim it down to make it have a much functionality as possible for a demo on the university Lan. The thing doesn't have wifi and things are not allowed on the Uni network...😂 the joys...
  2. Interestingly I actually needed the whole path for that one. It wanted the complete path to send an attachment in PHPMailer. It wouldn't take the /LifeSaverHTML/Details/20 It wanted the whole /var/www/html/LifeSaverHTML/Details/20 This code does it though there's probably one of those server commands would work too. $uri_dir = getcwd();
  3. Sorry guys I got it: - $uri_dir = dirname($_SERVER['REQUEST_URI']); echo $uri_dir; Might come in handy for someone in future
  4. I need to assign my current folder path to a variable. I keep getting this:- What I want is this:- That full path does weird stuff. Sometimes when I'm editing files, it's like I'm editing a ghost copy but not the actual file... Weird anyways. Below is some of the attempts I've tried... If I use this command:- //$uri = $_SERVER['REQUEST_URI']; It will give me what I need but with index.php tacked onto the end:- <?php //$pa = $_SERVER['PATH_TRANSLATED']; //echo $pa; //$uri = string dirname ( $path ); //echo $uri; //$ echo $PWD // current directory // current directory //echo getcwd() . "\n"; //chdir('cvs'); // current directory //echo getcwd() . "\n"; //$pa = basename(__DIR__); //echo $pa; //$pa = dirname(__FILE__); //echo $pa; $cur_dir = explode('\\', getcwd()); echo $cur_dir[count($cur_dir)-1]; ?> This first one returns a blank page without error, there's one that will return just the directory most are the www stuff. I suppose I could edit the string but surely there must be a function?
  5. Maxxd thx for the extra info. Sorry I've had this link open all this time, buried deep in my multiple research windows. I'm stuck at a part of this that I thought would be as easy as pie. Seeming not... sigh... gonna open another thread for it though as it's kind of unrelated.
  6. That's worked out nicely to send that variable. I'm not sure if Href will tell the phpmailer page to send the email though. I seem to remember it needed the form post method... but I could be wrong. I've some test to set up here and see if it works. . Thanks once again, I definitely wouldn't be sitting at this point without your help. 3 months to go and am freeeeee from uni...soon this project will be done. Enjoyable but can't wait to get finished... I'll let you know if it works.
  7. Nice, so the <??> is telling it to use the php variable... kk I'll give it a whirl.
  8. Yeh sorry Barand - I just literally noticed the post and ran into the problem simultaneously. I'm thinking about removing this button and using the Href instead. I'm sure I can change the href with css if I need to. This is the code. It will go to a page that sends an email - I want a variable for the attachment location. It then comes back to this page with a header function returning "email sent" The href doesn't seem to recognise the $uri. My first thought is the HTML has a different scope than the php. But that doesn't seem to have been my experience so far with php and html... <?php if(isset($_GET['Message'])){ echo $_GET['Message']; } $uri = $_SERVER['REQUEST_URI']; ?> <html> <body> <a href='test.php?id=$uri'>link to page2</a> <!-- <form action="index.php" method="POST"> <button type="submit">Send</button> </form> --> </body> </html>
  9. Not always it would seem... funny I was just trying to resolve this, when I spotted the message about your post @gw1500se <a href='test.php?id=$uri&user=John'>Dispatch</a> Seems to recognise the $uri as a string. Actually now I look at it this is pretty much the same issue...
  10. 😂 Two hours later and it was the most simplest change to your code that got me the variable as well Barand..! <td> <a href='Details/$id/index.php?id=$id'>$id</a> </td> I was adding in {{}} and .$id. and all sorts to try and get it working. Lol I suppose the $ is telling it the next part of the string is the variable. Silly me... You're a legend sir! I've got to do another one lil complicated bit, now. Well complicated for me... and I think I've at least got the basic functionality of this project working.
  11. Hi guys; I've managed to find my way into something of a maze. <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> I'm looking at this line in the code. I realise it's currently in the wrong syntax but I'm just trying multiple different variations. At the moment I'm actually just trying to make it go to a static link but my real goal is to - get it to pick up the id number, of the id row I click, and concatenate that with the rest of my address string. Then use that as the href. Something like this: - "'Details/' + $id + '/index.php'" It's really confusing me though inside this loop and for some reason the id number is being picked up as an int, by the looks of things. It's getting above my level of understanding. Any chance one of you masters would through a n00b a lifeline? This is my code below <!DOCTYPE html> <html> <head> <title>LifeSaver DB</title> <h1> LifeSaver Database </h1> </head> <body> <table> <tr> <th>Id</th> <th>Location</th> <th>Initials</th> <th>TimeStamp</th> <th>Notes</th> </tr> <?php $conn = mysqli_connect("localhost", "meh", "pas", "DB"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM LifeSaver1 ORDER BY id DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //for href row $id = $row['id']; $Footage = ['Footage']; echo "<tr> <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> <td>" . $row["Location"] . "</td> <td>" . $row["Initials"]. "</td> <td>" . $row["TimeStamp"]. "</td> <td>" . $row["Notes"] . "</td> </tr>";} //show table echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> <style> table, td, th { border: 1px solid black; margin: auto; } table { border-collapse: collapse; color: #000; <!--font colour --> font-family: monospace; font-size: 18px; text-align: center;} th { background-color: #337AFF; color: white; font-weight: bold; } tr:nth-child(odd) {background-color: #add8e6} </style> </html>
  12. @Barand You're a legend ! Thx so much, most of the day I'm trying to do that... Finally I can sleep...
  13. I have this working script below. I never managed to turn it into a function... I think it's because there's classes in it. I stopped that investigation and instead I choose to:- keep it on another page, trigger it with the a <form> button, then return to the form page using header location. This is probably much more elaborate than it needs to be... but it seems to be working fine. I'd like to print out "email sent" if successful. The collection of confusion at the end of this script, is me trying to get it to return the - "email sent" message <index.php> <?php require 'includes/PHPMailer.php'; require 'includes/SMTP.php'; require 'includes/Exception.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = "true"; $mail->SMTPSecure = "tls"; $mail->Port = "587"; $mail->Username = "email@gmail.com"; $mail->Password = "pass"; $mail->Subject = "Test email using PhPmailer"; $mail->setFrom("email@gmail.com"); $mail->isHTML(true); //$mail->addAttachment('img/movie.mp4'); $mail->Body = "<h1>This is a HTML heading</h1></br><p>This is a html title</p>"; $mail->addAddress("email@gmail.com"); if ($mail->Send() ) { echo "Email sent..!"; } else{ echo "Error..!"; } $mail->smtpClose(); ob_start(); $Message = urlencode("Email Sent"); header("Location:EmailBut.html?Message=".$Message); die; ob_flush(); ?> The stuff at the beginning of this next script is me trying to get it to print out email sent. I can get it to return the message in the URL but it won't print out. <EmailBut.html> <?php ob_start(); if(isset($_GET['Message'])){ echo $_GET['Message']; } echo $_GET['Message']; ob_flush(); ?> <html> <body> <form action="index.php" method="POST"> <button type="submit">Send</button> </form> </body> </html> Can you please give me a push in the right direct here?
  14. Yeh I know... I changed it it's ok.. n00b move lol 🤔
  15. @requinix- Hi Requinix thx for the reply. I was beginning to think I had a internet smell. To my great relief during the course of the troubleshooting I was doing for you, I managed to get it working! I've used a simple script, which I posted at the bottom for anyone in future, who might view the thread. As a side note one of the troubleshooting steps I was trying yesterday was - to define the script as a function. Why doesn't this load? It just gives me error 500. As far as I can tell it's the right syntax. I know the script inside the function works and I know this syntax works? What am I missing? <?php function EmailScript() { require 'includes/PHPMailer.php'; require 'includes/SMTP.php'; require 'includes/Exception.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = "true"; $mail->SMTPSecure = "tls"; $mail->Port = "587"; $mail->Username = "***********@gmail.com"; $mail->Password = "***********"; $mail->Subject = "Test email using PhPmailer"; $mail->setFrom("*********@gmail.com"); $mail->isHTML(true); //$mail->addAttachment('img/LifesaverFootage.mp4'); $mail->Body = "<h1>This is a HTML heading</h1></br><p>This is a html title</p>"; $mail->addAddress("lifesaversecur@gmail.com"); if ($mail->Send() ) { echo "Email sent..!"; } else{ echo "Error..!"; } $mail->smtpClose(); } EmailScript(); ?> Here's the working script for anyone in future: - just put the EmailButton.html in the same directory as the php loading from index.php or make them on the same page and adjust the code. <html> <body> <form action="index.php" method="POST"> <button type="submit">Send</button> </form> </body> </html>
  • 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.