|
|
|
SELECT Databases มากกว่า 1 ฐานข้อมลูขึ้นไป ทำยังไงครับ และ วิธีเขียน Connect DB ที่ถูกต้องเขียนแบบไหน |
|
|
|
|
|
|
|
ไหนๆก็เริ่มต้นแล้ว เขียนโดย mysqli เลยครับ
|
|
|
|
|
Date :
2017-04-18 12:58:52 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้แล้วครับ พอดีได้วิธีนี้มาแทน คือ ถ้าหาก Table ของ $db1="stock_d"; AND $db2="staffdata"; ให้อ้างอีงถืง Database ตัวนั้น เช่น บรรทัด stock_d.admin
$sqlAdmin="SELECT AdminID,AdminName,AdminUser,AdminPass FROM stock_d.admin
จะประมาณนี้ ขอบคุณมากๆครับ มีโอกาสจะลองศีกษา mysqli ดู Thank you Mr.กล้า
<?php
session_start();
ob_start();
require('include/db_connect.php');
require('include/function.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Custom Login Form Styling with CSS3" />
<meta name="keywords" content="css3, login, form, custom, input, submit, button, html5, placeholder" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="login/css/style.css" />
<script src="login/js/modernizr.custom.63321.js"></script>
<!--[if lte IE 7]><style>.main{display:none;} .support-note .note-ie{display:block;}</style><![endif]-->
<title>Infromation Login</title>
<style>
body {
background: #e1c192 url(login/images/wood_pattern.jpg);
}
</style>
<?php //=========คำสั่ง alert ===========?>
<script language="javascript">
function chkinp(form){
if(form.username.value==""){
alert("ກະລຸນາປ້ອນຂໍ້ມູນ username !!!")
form.username.focus();
return false;
}else if(form.password.value==""){
alert("ກະລຸນາປ້ອນຂໍ້ມູນ password !!!")
form.password.focus();
return false;
}
}
window.onload=function(){
document.getElementById("username").focus();
}
</script>
</head>
<body>
<div class="container">
<header>
<h1><strong>ຍິນດີຕ້ອນຮັບເຂົ້າສູ່ລະບົບ</strong></h1>
<h2><strong>Information System Login</strong></h2>
</header>
<?php //=========table login===========?>
<section class="main">
<form name="form1" method="post" action="" class="form-2" onSubmit="return chkinp(this)">
<h1><span class="log-in">Log in</span></h1>
<p class="float">
<label for="username"><i class="icon-user"></i>Username</label>
<input type="text" name="username" placeholder="Username" id="username" autocomplete="off">
</p>
<p class="float">
<label for="password"><i class="icon-lock"></i>Password</label>
<input type="password" name="password" placeholder="Password" class="showpassword" id="password" autocomplete="off">
</p>
<p class="clearfix">
<input type="submit" name="submit" value="Log in" >
<input name="login" type="hidden" id="login" value="login">
</p>
</form>
</section>
<header>
<h1><a href='index.php'>ຫນ້າຫລັກ</a></h1>
<?php
if(isset($_POST['login'])){
$sqlAdmin="SELECT AdminID,AdminName,AdminUser,AdminPass
FROM stock_d.admin
WHERE (AdminUser='".$_POST['username']."')
AND (AdminPass='".$_POST['password']."')";
$resultAdmin=mysql_query($sqlAdmin,$c1);
$NumAdmin=mysql_num_rows($resultAdmin);
$rAdmin=mysql_fetch_array($resultAdmin);
if
($NumAdmin>'0')
{
$_SESSION['login_true_AdminID']=$rAdmin['AdminID'];
$_SESSION['lname']=$rAdmin['AdminName'];
$_SESSION['lusername']=$rAdmin['AdminUser'];
$_SESSION['lpassword']=$rAdmin['AdminPass'];
$_SESSION['lstatus']='Admin';
echo "<img src='img_loader/loading3.gif' width='105' height='16' />";
echo "<BR>";
echo "<span style='color:#000099;'>";
echo "ຍິນດີຕ້ອນຮັບທ່ານ $rAdmin[AdminName] ເຂົ້າສູ່ລະບົບ !!!";
echo "</span>";
echo "<meta http-equiv='refresh' content='2;url=./main.php'>";
exit();
}else{
echo "<img src='img_loader/loading2.gif' width='100' height='100' />";
echo "<BR>";
echo "<span style='color:#FF0000;'>";
echo "ບໍ່ສາມາດເຂົ້າສູ່ລະບົບໄດ້ ກະລຸນາລອງໃໝ່ອີກຄັ້ງ";
echo "</span>";
echo "<meta http-equiv='refresh' content='2;url=./login.php'>";
}
}
?>
</header>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".showpassword").each(function(index,input) {
var $input = $(input);
$("<p class='opt'/>").append(
$("<input type='checkbox' class='showpasswordcheckbox' id='showPassword' />").click(function() {
var change = $(this).is(":checked") ? "text" : "password";
var rep = $("<input placeholder='Password' type='" + change + "' />")
.attr("id", $input.attr("id"))
.attr("name", $input.attr("name"))
.attr('class', $input.attr('class'))
.val($input.val())
.insertBefore($input);
$input.remove();
$input = rep;
})
).append($("<label for='showPassword'/>").text("Show password")).insertAfter($input.parent());
});
$('#showPassword').click(function(){
if($("#showPassword").is(":checked")) {
$('.icon-lock').addClass('icon-unlock');
$('.icon-unlock').removeClass('icon-lock');
} else {
$('.icon-unlock').addClass('icon-lock');
$('.icon-lock').removeClass('icon-unlock');
}
});
});
</script>
</body>
</html>
<?php
ob_end_flush();
mysql_close($d1,$db1,$c1);
mysql_close($d2,$db2,$c1);
exit();
?>
|
|
|
|
|
Date :
2017-04-18 13:34:42 |
By :
Bouasavanh HararRock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แค่จะบอกว่า PHP ใหม่ๆ มันไม่รองรับการทำงาน mysql แล้วครับ อยากยอกเท่านั้นจริงๆ
|
|
|
|
|
Date :
2017-04-18 14:47:20 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|