Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

How to connect to a Database on a Webserver

General discussions related to php

Moderators: macek, egami, gesf

How to connect to a Database on a Webserver

Postby rallepralle » Sun Nov 03, 2013 7:29 am

Hi,

I'm using Win 7 and mySQL-DB. With XAMPP I'm already able to access a local DB on my computer. But how do I access a DB on an online Webserver?

I'm trying to create a logIn form where users can enter a password and username protected site. This is the code I'm able to access my DB offline (localhost):

Code: Select all
<?php
    $inputuser = mysql_real_escape_string($_POST['user']);
    $inputpass = $_POST['pass'];

    $user="root";
    $password="";
    $database="testDatabase";

    $connect = mysql_connect("localhost", $user, $password);
    @mysql_select_db($database) or ("Database not found");

    $query="SELECT * FROM User WHERE UserName='$inputuser'";
    $querypass="SELECT * FROM User WHERE Password= '$inputpass'";

    $result=mysql_query($query);
    $resultpass=mysql_query($querypass);

    $row=mysql_fetch_array($result);
    $rowpass=mysql_fetch_array($resultpass);

    $serveruser=$row["UserName"];
    $serverpass=$rowpass["Password"];

/*  echo $inputpass;
    echo "server-user: ";
    echo $serveruser;
    echo "server: ";
    echo $serverpass;
*/  if ($serveruser&&$serverpass){
        if (!$result){
            die("Username or passwor is invalid");
        }
        mysql_close();

        if ($inputpass==$serverpass){

            header('Location:/home.php');
        }
    }
    else{
        header('Location:/fail.php');
    }
?>


Now I want to do the very same with a DB on a "real" webserver. What do I have to change in the code above?
For this case, let's assume these:
My provider: http://www.exampleprovider.com
Location where my DB is located: rdbms.exampleprovider.com
My Database name: DBreal
The username to my Database: DBrealName
The password to my Database: DBrealPassword

I tried this among others:
I replaced "localhost" with "rdbms.exampleprovider.com"
I assigned "$database" with "DBreal"
I assigned "$user" with "DBrealName"
I assigned "$password" with "DBrealPassword"

....but I only retrieved values for $serverpass. The value for $serveruser is empty. Could could say what I should put in the parameters? Thanks in advance.
rallepralle
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Nov 03, 2013 7:22 am

Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.