I'm running into an issue while trying to link a MySQL database to a PHP file.
Im trying to setup this PHP login system from Github and currently I'm trying to setup the dbconf.php file. This is the code where I'm trying to link the database to.
<?php
//DATABASE CONNECTION VARIABLES
$host = "localhost"; // Host name
$username = "user"; // Mysql username
$password = "password"; // Mysql password
$db_name = "22445671_login"; // Database name
//DO NOT CHANGE BELOW THIS LINE UNLESS YOU CHANGE THE NAMES OF
THE MEMBERS AND LOGINATTEMPTS TABLES
$tbl_prefix = ""; //***PLANNED FEATURE, LEAVE VALUE BLANK FOR NOW***
Prefix for all database tables
$tbl_members = $tbl_prefix."members";
$tbl_attempts = $tbl_prefix."loginAttempts";
The MySQL Database is named 22445671_login
I am just looking for a way to link the MySQL database to my document
Any help is greatly appreciated, thanks.
As put into my original question before it was removed. My website is hosted at at-space which comes with a PHPmyAdmin account linked to my website, I dont know how to link the MySQL database since I don't know if the username and password are just username and password. And I dont know if the host would be 1. My Website 2. atspace or 3. PHPMyAdmin
Where is your database hosted?
You might need to replace "localhost" with the hostname of your server:
$host = "localhost"; // Host name
Make sure you have the correct username and password
Make sure the user has the necessary permissions
Not sure if PMA has this feature, but SIDU has this feature:
<?php
$url = 'http://example.com/sidu54/conn.php'
.'?conn[host]='. $host
.'&conn[user]='. $username
.'&conn[pass]='. $password
// OR .'&conn[pass]='. $encryped_pass .'&conn[penc]=1'
.'&conn[dbs]='. $db_name
.'&conn[eng]=PDO_mysql'
.'&conn[char]=utf8'
.'&cmd=Connect'
.'&url=db.php'
.'&id=1,'. $db_name;
echo 'Click here to manage database';
Related
Ok so i am making account system for my website. I am using freewebhostingarea as host. But i dont know what is servername(for connecting to database). Can you help me? Here is my code for connecting:
<?php
$servername = "";
$server = "root";
$password = "my password";
$dbName = "name";
$conn = mysqli_connect($servername, $server, $password, $dbName);
?>
I dont know what is $servername for freewebhoatingarea. Pls reply.
It's all the same actually . I want you to try this 4 steps
After you hit create databaase it will give you an option to name/rename your database so save that name to something like a notepad for your reference
(e.g) freehosting_db_(sampledatabase)
Next to that it that before you hit next on the creation of database kindly remember that password that you are going to make and like the name of the website save it to a notepad so you can remember the password
(e.g) xHsnaAXa123 -> password database
Mostly the server always localhost on SOME freehosting
The servername is automatically generated so look for it. It will be something like
(e.g) freehosting_db_(sampledatabase)_user
And to set that up
$servername = "freehosting_db_(sampledatabase)_user";
$server = "localhost";
$password = "xHsnaAXa123";
$dbName = "freehosting_db_(sampledatabase)";
PS: This is mostly how you setup a connection from your database to your server . But it is always depends on the the hosting that you are going to use . Godadday, Hostgator, 000webhostingapp, they are all alike on how setting it up .
I am beginner with creating websites
I have already created a website by html and ccs
and also i created the database by my sql queries
Now still link the database with my website in xampp server
But I have no idea how to do it
I search google i found one explanation that told me to create db_connection.php file in htdocs where my website files located and import my database file to myphp admin
I did all these steps
I don't know what is the next step
should i write any codes in each page code of my website or not
I hope someone help me
I will really thankful for him/her
In your db_connection.php you should write
$dbServername = "localhost"; //if you use xampp, it will be localhost
$dbUsername = "yourUsername"; //standart login is root
$dbPassword = "yourPassword"; //standart password is none, so leave it empty
$dbName = "yourDbName"; //place your db name here
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
Now you are connected to your db. Include this file where you need to perform query's.
$myhost = "";
$myuser = "";
$mypass = "";
$mydb = "";
Where in the PhpMyAdmin panel would I find these details? I can't find them on my hosting panel! (I use MediaTemple Grid Hosting)
I have the username and password but don't know what to put for myhost and mydb!
My PHPMyAdmin Username to login looks like this: db111111_test
But with different numbers after db.
Would db111111 be the db or would _test or test be the db? Also what would the host be?
http://(ip-of-server)/phpmyadmin
or you can read this
https://mediatemple.net/community/products/dv/204643690/managing-a-mysql-database-with-phpmyadmin
quick mysql question.
I'm new at php/mysql and followed a tutorial(php/mysql for dummies) so I don't really know what I did wrong or if the tutorial is wrong.
I have a file, "database_connections.inc", that looks like this:
<?php
$user = "username";
$host = "host";
$password = "password";
$database = "database";
?>
With the actual credentials not included for obvious reasons.
Then in another file, login.php, I have:
include("database_connections.inc");
$cxn = mysqli_connect($host,$user,$password,$database)
or die("Query died: Couldnt connect to server.");
I get an error message with the "or die" text, accompanied by a warning:
host xxxxx.000webhost.com is not allowed to connect to this mysql server in....
Why not? I'm sure my credentials are all correct.
I've read in a few places to run some shell statements...but can't really do that, I'm on Windows.
I'm using phpMyAdmin, so hopefully I can do something from there?
Open "database_connections.inc" and change it to look like this:
<?php
$user = "root";
$host = "localhost";
$password = "";
$database = "test";
?>
MySQL is by default configured to work with localhost (or 127.0.0.1), in order to allow "host xxxxx.000webhost.com" as host, open phpMyAdmin and select "SQL" and execute this query;
GRANT ALL ON your_database_name.* TO your_user#your_host_xx.xxx.xx.xx IDENTIFIED BY 'your_password';
Go into PHPMyAdmin, and edit your user.
Under Login Information, there should be an option for "Host"- try adding xxxxx.000webhost.com.
Basicly, i've been doing a lot of searching around and still haven't found anything that solves the issue.
I am trying to connect my application to a database that is ran and hosted by a company, on an external server (we already use this database for a application we run on users computers)
I want to query the database for a login, so that when a user enters in his username and password on my app, it will compair these details with the details in the database, and reply back, stating if these credentials are correct, or not, and allowing the user to see a different page which will pull specific details from the database for that user (but thats something i need to solve in the future)
my main issue at the moment, is I cant seem to get the app to be able to connect to the database, currently I am using a WAMP server to host a php file I made...
NOTE: i will be using "user" and "pass" instead of the actual username and password I have
<?php
//connecting
//server, username, password, database
$dbhost = 'external ip entered here';
$dbuser = 'user';
$dbpass = 'pass';
$dbdb = 'datbasename';
//connect to mySQL
$connect = mysql_connect ($dbhost,$dbuser,$dbpass) or die("Connection error");
//select the database
mysql_select_db($dbdb) or die ("database selection error");
//Retrieve the login details via POST
$username=$_POST['username'];
$password=$_POST['password'];
//Query the table
$query="SELECT llogint,lpasint FROM TCHAUFF (nolock)
WHERE llogint='$username' AND lpasint='$password'";
//check if there any results returned
$num = mysql_num_rows($query);
//if a record was found matching the details entered in the query
if($num == 1){
//create a while loop that places the returned data into an array
while($list=mysql_fetch_assoc($query)){
//store the returned data into variable
$output = $list;
//encode the returned data in JSON format
echo json_encode( $output );
//close the connection
mysql_close();
}}
?>
I don't think theirs any issue with the php file to be honest but please correct me if so haha!
the problem i'm having is if I try and run this php file from WAMP by placing the file into the www folder and going to localhost/androidtest.php
I get an error saying Warning: mysql_connect(): No connection could be made because the target machine actively refused it
I have tried literally every solution i could find,
added this information to the config.inc.php file
/* Server: UserSeaCogi[1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'external database';
$cfg['Servers'][$i]['host'] = 'external ip entered here';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'user';
$cfg['Servers'][$i]['password'] = 'pass';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
I'm lost for ideas!
i have added
bind-address = 0.0.0.0
to the my.ini file
but am thinking its something to do with the way i have WAMP setup, but I cant seem to find what to change.
I also know I definitely have access to the database, as I can run querys from it if I add it to visual studio...one thing to note..it is a 2003 server...i know that had certain limitations with visual studio not sure about with android?
Thanks in advance
In your php code
mysql_select_db($dbdb)
should be
mysql_select_db($dbdb,$connect) ;
Then add these lines
$result = mysql_query($query, $connect);
$num = mysql_num_rows($result);