How To Connect Login With PHP Script Code Into Mysql Database From A File
RegisterLogin
How To Connect Login With PHP Script Code Into Mysql Database From A File
Post Description: How To Connect Login With PHP Script Code Into Mysql Database From A File
Tags: How, To, Connect, Login, With, PHP, Script, Code, Into, Mysql, Database, From, A, File
This Post Was Posted On Feb 29, 2008 By web hosting #1475
Post Description: How To Connect Login With PHP Script Code Into Mysql Database From A File
Tags: How, To, Connect, Login, With, PHP, Script, Code, Into, Mysql, Database, From, A, File
This Post Was Posted On Feb 29, 2008 By web hosting #1475
How To Connect Login With PHP Script Code Into Mysql Database From A File by web hosting
this is what you will need to know before this works:
1. your database hostname. Most of the time its called localhost but depending on your hosting company, they may have a different name, if you are not sure, contact them
2. your database user name: if you don't know this, contact your hosting company
3. your database user password: if you don't know this, contact your hosting company
4. you database name: this is the database you are going to be using for your script. if you don't know this, contact your hosting company
so lets say i have a database called "user_list", my user name is "dbu2", my user password is "mypassd" and my mysql hostname is "localhost" this is how i would write the connection function of the script:
this is an example you can use to connect to your databases:
Code:
<?php
###### ENTER YOUR DATABASE INFORMATION HERE #######
$hostname = "localhost";
$username ="dbu2";
$userpassword = "mypassd";
$database_name = "user_list";
###########################################
$db = mysql_connect($hostname, $username , $userpassword);
mysql_select_db($database_name,$db);
?>
###### ENTER YOUR DATABASE INFORMATION HERE #######
$hostname = "localhost";
$username ="dbu2";
$userpassword = "mypassd";
$database_name = "user_list";
###########################################
$db = mysql_connect($hostname, $username , $userpassword);
mysql_select_db($database_name,$db);
?>
now that i have the connection, its time to get and display the database information form mysql database tables. to get the informatio out of the database table i will be using the SELECT function in mysql. so lets say the table in the user_list database is called "my_table" and i want to display the "first_name" field, this is how i would do it"
Code:
$sql = "SELECT first_name FROM my_table";
$result = mysql_query($sql ,$db);
if ($myrow = mysql_fetch_array($result))
{
do
{
echo"Name: $myrow[first_name ]<br>";
}
while ($myrow = mysql_fetch_array($result));
}
so now to put the whole script together:
Code:
<?php
###### ENTER YOUR DATABASE INFORMATION HERE #######
$hostname = "localhost";
$username ="dbu2";
$userpassword = "mypassd";
$database_name = "user_list";
###########################################
$db = mysql_connect($hostname, $username , $userpassword);
mysql_select_db($database_name,$db);
$sql = "SELECT first_name FROM my_table";
$result = mysql_query($sql ,$db);
if ($myrow = mysql_fetch_array($result))
{
do
{
echo"Name: $myrow[first_name ]<br>";
}
while ($myrow = mysql_fetch_array($result));
}
###### ENTER YOUR DATABASE INFORMATION HERE #######
$hostname = "localhost";
$username ="dbu2";
$userpassword = "mypassd";
$database_name = "user_list";
###########################################
$db = mysql_connect($hostname, $username , $userpassword);
mysql_select_db($database_name,$db);
$sql = "SELECT first_name FROM my_table";
$result = mysql_query($sql ,$db);
if ($myrow = mysql_fetch_array($result))
{
do
{
echo"Name: $myrow[first_name ]<br>";
}
while ($myrow = mysql_fetch_array($result));
}
continuing with my example, lets say i have 3 visitors in my database and the database information looks like this:
uid first_name last_name
------------------------------------
1 tommy usiras
2 luke skywalker
3 standford moleculas
this is what my script would display:
Code:
tommy
luke
standford
luke
standford
if you have any question, you can reply to my post here.
Thanks to the folks at www.webune.com web hosting for their support on this tutorial guide.
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
©2012 Webune Forums - Sat Dec 15, 2012 9:02 am
Powered by: Webune Forums V3
Powered by: Webune Forums V3