My connection file is conn.php, adminname and password are the table field name and form text box name. when this code run on server FTP it shows No database selected. But i include connection file and update database on FTP server. This code is run on local wamp server.
**my login coding is:**
// this is my login page.
<?php
session_start();
// start here session
include('conn.php');
// here include connection file
if(isset($_POST['login']))
{
$sql="select * from admin where adminname='".$_POST['adminname']."'and password='".$_POST['password']."'";
// this is my sql query which select adminname and password in table
$result=mysql_query($sql) or die(mysql_error());
if($result)
{
$row=mysql_fetch_array($result);
if(mysql_num_rows($result)>0)
{
$_SESSION['admin']=$row['adminname'];
header("location:home.php");
}
else
{
header("location:index.php");
}
}
}
?>
Make sure about few things:
tricky way to make a database connection that works in your localhost and real server is:
$host = $_SERVER['HOST_NAME'];
if( $host == "localhost" ){
// localhost settings
}
else{
// Server Settings
}
it's just a simple trick.
add one line in conn file after getting connection from database
<?php
mysql_select_db ( string $database_name);
?>