Jump to content

StevenOliver

Members
  • Posts

    237
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by StevenOliver

  1. Unfortunately, I have google searched this exact thing, and found too many conflicting "solutions." Each "solution" proposes a line of code, followed by, "well, this worked for me...". And, I don't want to mislearn yet another "hack." Rather, I'd like to know the correct way to do this. So here is a properly worded question: For a sudo user to create files in the /var/www/html directory of an Apache2/Ubuntu 20.04 cofiguration, what are the "best practices" lines of chmod and chown code to accomplish this? Thank you
  2. But I am a member of the www-group. I thought that was the point of "becoming a member." Would you please explain what is the point of being a member of the www-data group if I do not inherit its privileges?
  3. 755 means: Owner can read, write, execute. Everyone else can read, execute. When I stat my d and f: 755 drwxr-xr-x www-data www-data Aug 5 20:18 www 755 drwxr-xr-x www-data www-data Aug 5 20:19 html 644 -rw-r--r-- www-data www-data Aug 1 18:12 index.html ... and check if I'm a member of www-data.... $ groups //command line My_User_Name sudo www-data // result So, www-data owns the files. And, I'm a member of www-data. As a member of www-data, I should also be able to write. What am I missing?
  4. Unless you really want 7.3, you know there is PHP 7.4 available, right?
  5. On Ubuntu 20.04, I've done this a hundred times and it's always worked fine: chown -R www-data:www-data /var/www/html usermod -aG www-data My_User_Name Today, when trying to write a file in html, I get a "Directory '.' is not writeable" error. All the directories are 755, all the files are 644, and I've verified I'm a member of www-data. What am I missing, please? Thank you. p.s. I know I can do "chown -R MyUserName:MyUserName /var/www/html" and then I can write to the directory... but I'm trying to figure out why on earth the above suddenly won't work.
  6. Barand, thank you. It does look naked without the ( ) though... mac_gyver, sorry I didn't know that.They sure are coming up with newfangled things nowadays!
  7. Okay, now you get to do what I've had to do a thousand times.... google your error message, click the first result and see which scenario applies to your script. Debugging goes like this: 1.) Error reporting (you now have that at the top of your page) 2.) Google your errors 3.) Fix your errors. p.s. I'm still bothered about your <form> tag which appears to have no action ... but I'm too lazy to read your code and see if you have a javascript form.submit() in there somewhere... p.s#2 ..and the line of code that reads: if(isset($_COOKIE["id"])) .... where is "id" anywhere on what you posted? I see a setcookie("user_id" ..... and obviously "id" is different than "user_id" so does that need fixin' ???
  8. ...it took me years to realize the best websites -- the ones on "page one of google" -- almost universally break every "SEO" rule, have the worst, most improperly formatted html, duplicate content, errors up the wazoo.... heck, if it were me, nowadays, and I wanted to be on page one of google, I would intentionally violate every SEO rule. Go ahead, check it out.... look at the top sites on google, NONE of them follow any rules! Then.... go to page 50 on google, and you'll find all the perfect "no errors" websites, with perfect un-duplicated titles, perfect html, pure as the driven snow. Page 50.
  9. 1.) Put this at the top of your page: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); ?> 2.) You have "include 'db_const.php';".... please make it like this: include('db_const.php'); 3.) Is the file "db_const.php" in the same directory as the page calling it? If your html page is in a subdirectory, e.g below the directory your db_const.php file is in, then you need your include to look like this: (include('../db_const.php'); 4.) I didn't have time to read all your html code, but I notice your <form> tag does nothing. It says <form method="post">, but post where? Usually a form tag must have an action="something.php" like this: <form method="post" action="the_page_to_post_to.php"> 5.) If after all of that the problem still persists, then put this at the top of your page: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); foreach($_POST as $var=>$val){ echo "$var....$val<BR>"; } ?> ... and then you can see exactly what you are posting, and if you are posting what you want to post. Those 5 steps should give you all the answers you need. ...one more thing, I know you're using a prepared query, but still, you should validate that the user is actually posting an email address. You'll have to google this one. You'll want to just verify that it is a valid email WITHOUT changing the email (no preg_replace or anything -- otherwise you might end up with someone else's email). Just validate that it is a real email address before sticking it in your database.
  10. Jodunno's answer is correct. However, because I'm a lazy typer, I use an old-school hack (not real css, but works!): <div align="center"> I'm centered </div> ... or, better yet: <?php echo '<div align="center"> I'm centered </div>'; ?> That way, your post won't be in the wrong place, as this is a "PHP coding help" forum 😀
  11. Especially when learning PHP (like I currently am), it is really really important to have the latest PHP and latest mySQL. I literally spent months on cleaning up my PHP 5 code only to realize that PHP 7.4 is available, and those months could have been spent learning how to code properly. So definitely upgrade your PHP and mySQL to the max. Email your shared hosting company if necessary... ask them to move you to a newer server, etc. THEN all you have to do is stick the Error Reporting code on top, and it (along with a few google searches) will actually teach you how to fix everything in your code. It is VERY satisfying to have error reporting ON, and to have no errors! Also, turn on mySQL error reporting, too (google how to do this).
  12. #1.) Put at TOP of your php scripts: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); (be sure to remove this when it goes live, you don't want public to see any errors). #2.) if((isset($_POST['submit'])) && (isset($_POST['search']) && ($_POST['search'] != NULL))) { $search = $mysqli->real_escape_string($_POST['search']); $result = $mysqli->query("SELECT * FROM careers WHERE JobTitle regexp $search"); #3.) "Job Title" or "Salary Low" etc., etc., you can't have two-word variables for mysql or php or anything. You need to do like this: jobTitle, or job_title, or jobtitle or SalaryLow, or salarylow or salary_low...... you can't have mysql columns or php variables named with words with spaces. #4.) Clean up your output. You have $output .="Job Title:$jobTitle<br /> and that's going to look like: Job Title:carpenter You would want $output .="Job Title: $jobTitle.<br /> so that it will look proper: Job Title: carpenter.
  13. Great questions, SaranacLake! I want to know the answer to this one, too! Here's my 2 cents: When database queries are super-important, my code always does a "select" immediately after the "insert," just to verify the important data really got inserted properly. So, maybe: 1.) Create a simple Member Record database (e.g. Username and ID) 2.) Create a 2nd database crossreferencing the Member Record with any data you can gather (shopping cart, session ID's, IP, date, time, etc.) 3.) Verify those records are created by doing a select after the insert 4.) If records created properly, then Payment Processor. 5.) Figure out how your PHP code will know if Payment was a success or not. I dunno this one. Maybe fun reading about event loops 6.) If success, php mail a "congratulations email" to customer 7.) If no success, php mail() yourself an error, so you can fix it quick. I'll definitely watch this thread!
  14. Inside your <form> tags, you have <textarea name="remark" But, you do not have a name="fullname" anywhere inside your <form> tag. Therefore, the variable "fullname" never gets submitted (and thus, $fullname=$_POST['fullname'] will always be null, unless you fix that). That is why, when in development mode, you need to have Error Reporting turned on. One of the errors you would have seen is "undefined index fullname" which likely would have led to you discovering the error. 1.) Error reporting ON, during development. 2.) Declare your variables (and indexes) 3.) Use "prepared statements," or at least sanitize your data when running user-submittable mySQLi code.
  15. Barand, thank you! And, thank you for the debugging tip. I've been using echo and print interchangeably. I like your idea. So..... Guess what I did this morning! I got a copy of O'Reilly's "Learning PHP," and I'm starting from the very very beginning. One page at a time. I just now learned that "echo" and "print" don't have to be lowercase. Seriously, I'm not kidding. I'm starting from the very beginning. I'm going to actually learn PHP!
  16. OMG.... you're right! Those 3 things already did happen, and still, no register_globals! 😀 />
  17. Your post "nobody cares about XHTML" makes me happy. I've always thought XHTML is ugly, with all their stupid closing tags, but I always felt bad for writing code that wasn't "the new modern XHTML" that everybody is using. I'm glad I waited. Now it is passe. Like saying "rad." :-) Hopefully if I wait long enough, "Register Globals" will come back, too 😀
  18. Kicken, thank you for the suggestion. It would be embarrassing for me to say I am very rusty on how to create functions. So I will use the function that you wrote. Speaking of functions, I'm trying to learn jQuery.... and when I see examples on how to do things via jQuery, they are always the 2 or 3 lines without the function wrapper..... and I don't know how to make a function 'wrapper' that I can call, like I do with Javascript :-) And, as far as PHP functions, I'm still trying to figure out why "return" is sometimes written on the last line (the functions always work without the word "return" at the end :-) (see how rusty I am :-) I'll also check out Xdebug. Thank you again!!
  19. And in live (non-development) environment, the die($mysqli->error) should be off for security reasons. If I'm wrong, sorry.... just my two cents worth :-)
  20. That is a new one for me - I didn't know there is a one-liner to see post values. I regularly use the following line of code almost all the time when I am debugging pages with a lot of inputs: print '<pre>';foreach($_POST as $var=>$val){ echo "$var......$val<BR>"; } print '</pre>'; I put it all on one line so I can "turn it off" with a hashmark # to the left. It gives me a nice itemized column. I don't have to strain my eyes or think too hard to see what variables and values were posted. And, if you change $_POST to $_REQUEST, it will show all <form method="GET"> variables as well (if you use get variables). <form> without a method="post" directive will default to "GET" ("GET" is where the url window of your browser will show all the variables and their values, like www.example.com/index.php?weekday=today&user=beginner&status=king&month=december Regarding HTML5, yes you can actually dictate what form each button uses..... but again, I'm not a fan of complexity. I ended up almost using HTML5 buttons on a page that would have had 2 forms, but I rewrote my code to keep it simple, using only one form per page.
  21. Okay, "while" loop.... my mistake; I apologize. I wrote "foreach" when I really meant "while." I am sorry you got caught up in my non-event. Best wishes, to you, too.
  22. That is cool! I noticed this fact just yesterday when I was examining the "Submit Reply" button on this site's page. The internet is advancing too fast for me :-)
  23. Correct. With buttons (other form values are different), I've never had the need to use the "value" portion of a button in my PHP processing. For me, the "value" is simply what's displayed to the visitor. In fact, if you completely leave out the value (like this: <input type="submit" name="movies">), your browser will give it a default name of "Submit" to the visitor. Correct. I'm assuming you have 3 buttons. Right? If so, the Silver Member will click the silver membership button (<input type="submit" name="silver_member" value="click me if you are silver"> ... and a Platinum member will click the platinum button (<input type="submit" name="platinum" value="Platinum Members Only"> ...etc. If your page is more complex, and you have ONE page, with ONE button, then the page would have to already "know" if the member is gold plat or silver. <?php session_start(); if ($_SESSION["membership"] == 'platinum'){ $button = '<input type="submit" name="platinum_content" value="click me">'; } elseif ($_SESSION["membership"] == 'gold') { $button = '<input type="submit" name="gold_content" value="click me">'; } elseif ($_SESSION["membership"] == 'silver') { $button = '<input type="submit" name="silver_stuff" value="click me">'; } else { $button = '<input type="submit" name="not_a_member" value="Click Here To Learn More">'; } echo '<html><body>'; echo 'Hey buddy, click here<BR>'; echo $button; echo '</body></html>'; ?> .... something like that. You get the idea.
  24. Take for example, a company might have a "contact" page. It has a <textarea></textarea> input window with a button under it. The button will usually say something generic like "Submit" or "Send" <form name="myonlyform" method="post" action="thank_you_page.php"> <textarea>Type Message Here</textarea> <input type="submit" name="message_from_customer" value="Send"> They might have a button an inch below it for urgent messages: Have an urgent message? Click here: <input type="submit" name="urgent" value="Send Urgent Message"> Then, your "thank_you_page.php" page will be a big "Thank you for contacting us page, that might look like this: <?php echo 'Thank you for contacting us." if(isset($_POST["urgent"])) { echo 'We are giving this our immediate attention, please stand by!'; } if(isset($_POST["message_from_customer"])){ echo 'Thank you for your message. We will get back to you in several months.'; } echo 'Have a nice day.'; ?>
×
×
  • 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.