cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution

How to Establish a database connection through a php script?

Hi guys,
Would just like to say im a total noob when it comes to these things especially when its godaddy. I am basically trying to set up a questions form for my website, and was wondering how i would connect the php script up to the database. I created a script this morning however my first encounter was a internal 500 server message and then after messing with it I received a blank white page, with no information storing within the data base.
I was thinking it may be due to insufficient or invalid user rights. For Example 
"%db = mysqli_connect("host", "user", "pass", "database") or die("Could not establish connection with Database.");
 What do i put into these things in order for the Connection to establish? 

I originally put localhost, root etc but i feel like that was wrong 

Thanks in Advance!
Sultan 🙂

1 ACCEPTED SOLUTION
Super User IV

@sultankhan19 

 

So a couple of things

 

1) You need to create the database first if you haven't already - You can do this via cPanel MySQL Database Wizard  & then using phpMyAdmin you can create a table in the database

 

2) You will want to use localhost for the host - that part is correct

 

3) There should be an error_log file in the file manager that you can see what the exact error message is 

 

You mention you are new to doing this sort of configuration - Here is a link that talks about PHP / SQL and inserting form data  https://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php

I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. Thank You Info If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community

View solution in original post

3 REPLIES 3
Super User IV

@sultankhan19 

 

So a couple of things

 

1) You need to create the database first if you haven't already - You can do this via cPanel MySQL Database Wizard  & then using phpMyAdmin you can create a table in the database

 

2) You will want to use localhost for the host - that part is correct

 

3) There should be an error_log file in the file manager that you can see what the exact error message is 

 

You mention you are new to doing this sort of configuration - Here is a link that talks about PHP / SQL and inserting form data  https://www.tutorialrepublic.com/php-tutorial/php-mysql-insert-query.php

I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. Thank You Info If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community

View solution in original post

Thank you very much PL281 I will have another go at it now, I created the database and all of that. in php my admin it shows as localhost with a number next to it which I believe is probably the port?

@sultankhan19 

 

Yes that is the port number, but for the PHP script you shouldn't need it 

I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. Thank You Info If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community