How to connect to my database

How to connect to me database if i use this code below?

[php]<?php
$ My_Host=lokalhost
$ My_username=XXXXX ( shall i print my own username for my database as i got from my server here?)
$ My_password=XXXXX ( shall i print my password here as i have to my database here?)
Code for connection
$ connect=mysql_connect ($ my_host, $ my_username, $ my_password) ( shall i type same as i type before , or only let it be as it is?) or die (mysql_error() )
echo '<b style = color: #298A08;">
Connect to My SQL ';
?>[/php]

Pls learn me so i learn right from the beginning.
Jan

Ok, There are many problems with your code. first your variable names can have any spaces in it don’t use space in between $ and words you use, and then you should use single or double quotes (’ or ") to enclose variable values and using a semicolon at the end of each line is must too. Here is the proper way to connect to a database.

[php]<?php

$host = 'localhost';
$user = 'Your_Database_Useranme';
$pass = 'Username_s_password';
$db = 'Your_database_name';

$conn = mysqli_connect($host, $user, $pass, $db);

if (mysqli_connect_errno()){

	die (mysqli_connect_error());
} else {

	echo "Successfully connected to the database";
}

?>[/php]

Why would you want to connect to a database? Are you going to create a script that involves databases or is it just for practice? If you are connecting to a database of your website (server) then there is an option in the cPanel named as “MySQL databases” open it create a new database and username for it and then you can use those value in the script above.

But I would strongly suggest to install a local web-server like WAMP, MAMP or XAMPP on your computer and then use it for practicing needs.

Tanks for replay tanzeelniazi
i want to lern how to get a registerform and a login for work so a member can be added to this data base for get login to my site
http://speedaters.com
You can see i have a form there but it dont be any as can use it.
Jan

OK, so you want to create a script for you site. Well first thing, checkout the admin Panel (cPanel) to see whether you have access to databases (if yes). Note down the whether your hosting company support MySQL or not (if yes). You are in luck you can move to the next step. 8)

If you use Windows then go to WAMP Website and install it. or if you use Mac then go to MAMP and install it on your PC.

Yes i have one database on Doteasy.com and i see in admin that i have created 2 table in this database named registreringsform and this table name is “Login,’;register”
Shall i use servername as i got from the serveroperator as exemple abcdef123 or my database name as exemple janxxx_registreringsform and table register for get the users to addin this register?
Jan

You can’t use credentials that are used to log in to your website’s admin panel. You’ll have to use your database username / password i.e. janxxx_

Sponsor our Newsletter | Privacy Policy | Terms of Service