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
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
there is no one error message
do I understand correctly? I change it dbname=bigrafi - bigrafic_bigrafi
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
After doing that, I checked and it gave the same message again.
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:
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
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
the important part is:
Access denied for user 'root'@'localhost' (using password: NO)
you'll have to use the correct credentials in your PHP filewhat's that correct credentials is it hosting username and password?
it's whatever username and password you need to use to access the database
i access database from cpanel right there
and one admin user i have
is that correct?
I don't know, give it a shot (and I really hope that's not your actual password)
yeah no :D I wrote as an example
didn't work same problem
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
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
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
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
github, gitlab, whichever
okay i dont post these sites
effectively, it's a bad idea in general to have credentials hardcoded in and not in an environment file somewhere outside your document root
how can i add the document root from outside
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 likelol 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.
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
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
that's usually a logic issue with something that has
header("Location: somewhere");
pointing at itselfCould it be from here?
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
do you know how can i send to main domain
you can only do that if you haven't sent any data to the browser yet though, so no print or echos before that
like that?
nope, exactly what I wrote
ah sorry
you're using the
header
function to send a Location
header, which understands relative paths on your base urldoes it have to be at the top
nope, it goes at the end when you're done
the
exit
stops executionheader goes right above exit
it was right in the first screenshot, you just needed the string inside
header()
to say Location: /
Isn't that right?
ah okay
sorry i deleted it
thank you so much you worked hard, you helped a lot
no worries, glad to help 🙂
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