php function doesn't work on hosting but working localhost

hello, I run my php code on xampp localhost is works. But running on host I getting this issue ' This page is not working www.bigrafi.com.tr is currently unable to process this request. HTTP ERROR 500 '
45 Replies
Jochem
Jochem•2y ago
you should have access to the error logs on the server, that will probably tell you exactly what is wrong from just your screenshots, I think your dbname might need to be bigrafic_bigrafi
fatihinn
fatihinnOP•2y ago
there is no one error message
fatihinn
fatihinnOP•2y ago
do I understand correctly? I change it dbname=bigrafi - bigrafic_bigrafi
Jochem
Jochem•2y ago
If this image is from your server's db manager, then I think that's the db name yeah https://media.discordapp.net/attachments/1043584946842894376/1043584948407382126/image.png
fatihinn
fatihinnOP•2y ago
After doing that, I checked and it gave the same message again.
Jochem
Jochem•2y ago
You could try adding this to the top of your page temporarily, it should print errors to the output and show them in the browser:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
make sure to remove that when you're done though, it can leak a lot of info to potential hackers if you leave it up
fatihinn
fatihinnOP•2y ago
thank u now i getting this error Fatal error: Uncaught PDOException: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO) in /home/bigrafic/public_html/bag.php:4 Stack trace: #0 /home/bigrafic/public_html/bag.php(4): PDO->__construct('mysql:host=loca...', 'root', '') #1 /home/bigrafic/public_html/addmessage.php(6): include('/home/bigrafic/...') #2 {main} thrown in /home/bigrafic/public_html/bag.php on line 4 and i removed error reporting code
Jochem
Jochem•2y ago
the important part is: Access denied for user 'root'@'localhost' (using password: NO) you'll have to use the correct credentials in your PHP file
fatihinn
fatihinnOP•2y ago
what's that correct credentials is it hosting username and password?
Jochem
Jochem•2y ago
it's whatever username and password you need to use to access the database
fatihinn
fatihinnOP•2y ago
i access database from cpanel right there
fatihinn
fatihinnOP•2y ago
and one admin user i have
fatihinn
fatihinnOP•2y ago
is that correct?
Jochem
Jochem•2y ago
I don't know, give it a shot (and I really hope that's not your actual password)
fatihinn
fatihinnOP•2y ago
yeah no :D I wrote as an example didn't work same problem
Jochem
Jochem•2y ago
as long as it keeps saying "Access denied for user", it's a credentials issue you probably have to set up a user in phpmyadmin, or check if you have any db credentials they sent you or something, I'm not familiar with cPanel and haven't used phpmyadmin in an Age
fatihinn
fatihinnOP•2y ago
thank you so much. i worked. by ftp username and password Do you have a problem with typing ftp username and password into php? now addmessage.php page going to db but Refreshing addmessage.php every second
Jochem
Jochem•2y ago
it's a bit dangerous, if you ever intend to check stuff into git or something. You don't want to have those values in a public place not sure what you mean with that last sentence
fatihinn
fatihinnOP•2y ago
websitename/addmessage.php url refreshing again every second i do not want publish my docs on git etc. Only I want publishing on google by hosting When you said 'git' did you mean github? I hope it won't be a problem, just post it on google
Jochem
Jochem•2y ago
github, gitlab, whichever
fatihinn
fatihinnOP•2y ago
okay i dont post these sites
Jochem
Jochem•2y ago
effectively, it's a bad idea in general to have credentials hardcoded in and not in an environment file somewhere outside your document root
fatihinn
fatihinnOP•2y ago
how can i add the document root from outside
Jochem
Jochem•2y ago
the document root is where the web server finds your files and serves them. Usually with PHP you'd include your config info, like your db connection info, in a .ini file and put that file somewhere else on your server, outside of where the webserver will serve your files to the public. Then in PHP you simply refer to the absolute path (so /this/is/your/config.ini instead if ./config.ini) of the config file, and use parse_ini_file to get the values out, and use them in your application https://www.php.net/manual/en/function.parse-ini-file.php it's not something I can tell you exactly how to do though, I have no idea what your setup looks like, or what the rest of your code looks like
fatihinn
fatihinnOP•2y ago
lol little bit confused hope so I can do it @jochemm Do you mind having a username and password on root until I do what you say? I know that the user entering the site does not have direct access to the php hardcode.
Jochem
Jochem•2y ago
it's a potential security issue, but as long as nothing goes wrong and your code gets exposed, or your webserver decides to start serving PHP files instead of feeding them to the interpreter, it won't do anything
fatihinn
fatihinnOP•2y ago
okay thank u so much by the way one more problem I have clicking the button after content go to database but refreshing that page every sec. not going anywhere
Jochem
Jochem•2y ago
that's usually a logic issue with something that has header("Location: somewhere"); pointing at itself
fatihinn
fatihinnOP•2y ago
fatihinn
fatihinnOP•2y ago
Could it be from here?
Jochem
Jochem•2y ago
that should send you to the main domain, but if that's also on the main page that would probably be what's causing the refreshing yeah
fatihinn
fatihinnOP•2y ago
do you know how can i send to main domain
Jochem
Jochem•2y ago
header("Location: /");
exit;
header("Location: /");
exit;
you can only do that if you haven't sent any data to the browser yet though, so no print or echos before that
fatihinn
fatihinnOP•2y ago
like that?
Jochem
Jochem•2y ago
nope, exactly what I wrote
fatihinn
fatihinnOP•2y ago
ah sorry
Jochem
Jochem•2y ago
you're using the header function to send a Location header, which understands relative paths on your base url
fatihinn
fatihinnOP•2y ago
fatihinn
fatihinnOP•2y ago
does it have to be at the top
Jochem
Jochem•2y ago
nope, it goes at the end when you're done the exit stops execution
fatihinn
fatihinnOP•2y ago
Jochem
Jochem•2y ago
header goes right above exit it was right in the first screenshot, you just needed the string inside header() to say Location: /
fatihinn
fatihinnOP•2y ago
Isn't that right? ah okay sorry i deleted it thank you so much you worked hard, you helped a lot
Jochem
Jochem•2y ago
no worries, glad to help 🙂
fatihinn
fatihinnOP•2y ago
Bro can u help again pls I'm getting one issue? 🙂 I added new title on #back-end phpMyAdmin getting error. explained a little but I don't quite understand what I should do
Want results from more Discord servers?
Add your server