Results 1 to 5 of 5

Thread: Help with database

  1. #1
    Join Date
    Jan 2015
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help with database

    Hello,

    I'm struggling greatly connecting my php page to a database (this is my first time). I'm using c-panel and phpMyAdmin on my domain mmiles hosted by Arvixe.

    1. First I went to MySql Databases and called it secure_login and the database has the name: mmiles_secure_login
    2. Next I created user e*****s with a password of 1234****, then added user e*****s to the database
    3. Then I logged into phpMyAdmin and on the left side, clicked mmiles_secure_login and created a table called User
    4. On this table, I created several rows that can be seen in the structure for UserID, FirstName, LastName, Email, and Password

    I have no idea where the mySql database saves, but I assume php knows where to look???

    5. I add this blip of code to my index.php page:

    Code:
    <?php
    	
    	$connection = mysql_connect("localhost","root","") or die("There was an error loading the database!");
    	mysql_select_db("mmiles_secure_login", $connection);
    ?>
    I keep getting "There was an error loading the database!" So I tried changing 'root' to 'e*****s' and '1234****', but that also did not work. I've tried several other methods listed online but cannot even get past getting the php page to recognize a database even exists so usually can't even get past step one of every online resource I can find on the subject. Any ideas?
    Last edited by james438; 11-15-2015 at 07:19 PM. Reason: removed sensitive data

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,875
    Thanks
    92
    Thanked 97 Times in 95 Posts

    Default

    Try the following instead:

    Hostname: 127.0.0.1
    username: your_user
    password: your_pass
    database: sakila

    Code:
    $mysqli = new mysqli('127.0.0.1', 'your_user', 'your_pass', 'sakila');
    reference

    Below is a more realistic example of how it looks for me and pulls and displays a title where the ID is "3" and the table name is "article". The hostname below is using random numbers instead of the actual numbers and the part that says "localhost" is renamed so as to protect the actual name of my database.

    Code:
    <?php
    $conn = new mysqli("localhost.db.039850.hostedresource.com", "username", "password", "dbname");
    mysqli_select_db($conn,"dbname") or die(mysqli_error());
    
    $ID=3;
    $get_addresses        = "SELECT ID, title FROM article WHERE = $ID";
       $get_addresses_res = mysqli_query($conn,$get_addresses);
           $add_info      = mysqli_fetch_array($get_addresses_res);
               $title        = $add_info['title'];
    echo "$ID";
    ?>
    Notice that mysqli() function is being used instead of the deprecated mysql().
    Last edited by james438; 11-15-2015 at 07:17 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Jan 2015
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Got it, thanks. Was actually the user name. The hosting site had the domain name appended to the front of the user name and once I took that into account, it worked fine.

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,875
    Thanks
    92
    Thanked 97 Times in 95 Posts

    Default

    I'm glad you were able to get it working, but I hope you moved away from the deprecated (outdated) mysql.
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Jan 2015
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by james438 View Post
    I'm glad you were able to get it working, but I hope you moved away from the deprecated (outdated) mysql.

    Yes, I did, lol!

    $conn = new mysqli($servername, $username, $password);

Similar Threads

  1. Database is down
    By cherubrock74 in forum PHP
    Replies: 1
    Last Post: 05-16-2009, 08:18 PM
  2. How should I set up my database???
    By Dirt_Diver in forum MySQL and other databases
    Replies: 9
    Last Post: 08-15-2008, 12:44 PM
  3. Help with big database?
    By Drewsterritz in forum MySQL and other databases
    Replies: 1
    Last Post: 05-23-2008, 08:38 PM
  4. My Own SQL database
    By wentwooddownhill in forum MySQL and other databases
    Replies: 3
    Last Post: 06-01-2007, 10:20 PM
  5. XML vs Database with PHP
    By pavmoxo in forum PHP
    Replies: 1
    Last Post: 11-13-2006, 12:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •