Posts

PHP#33MySQL#29 - Đếm lượt truy cập (KẾT THÚC KHÓA HỌC)

Image
//hitcounter.php <?php session_start();  ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php  include("../connect.php"); //cập nhật số luowhtj truy cập: $sl="update counter set cnt=cnt+1"; mysqli_query($link,$sl); //Lấy dữ liệu số lượt truy cập để hiển thị ra web: $sl2="select * from counter"; $kq=mysqli_query($link,$sl2); $d=mysqli_fetch_array($kq); //Định dạng: $chuoi=str_pad($d['cnt'],6,"0",STR_PAD_LEFT); $luottrycap=""; for($i=0;$i<strlen($chuoi);$i++) { $tam=substr($chuoi,$i,1); $luottrycap.="<img src='images/$tam.png'/>"; } /*-Khi user truy cập vào website: +lần đầu tuy cập: Lưu thông tin của user lên csdl +Sau lần đầu tiên: cập nhtaaj lastvisit - Xóa các dòng dữ liệu quá 1 phút (Quy ước thời gian để khẳng định online hay offline: 1 phút) - Thống kê số liệu người dùng ...

PHP#32MySQL#28 - Ajax3 + EMAIL

Image
//connect.php <?php $link=@mysqli_connect("localhost","root","") or die("Khong the ket noi den server"); mysqli_select_db($link,"webtintuc") or die ("Kiem tra lai ten database!"); mysqli_query($link,"set names 'utf8'"); ?>

PHP#31MySQL#27 - Ajax2

Image
//checkuser.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <script type="text/javascript" src="jquery-3.6.0.js"></script> </head> <body> <script type="text/javascript">  $(document).ready(function(){ $("#username").blur(function(){ $.ajax({                     type:"POST",                     url:"xuly_checkuser.php",                     data:"user="+$("#username").val(),                     success:function(abc) {                         if(abc=="1") $("#kq").html("User này đã tồn tại. Mời bạn chọn user khác!"); else { $("#kq").html("User này chưa có. Bạn có thể sử dụng"); ...

PHP#30MySQL#26 - Ajax

Image

PHP#29MySQL#25 - Captcha & Bình chọn

Image
//CAPTCHA: vidu.php <?php session_start(); //phát sinh 6 ký tự ngẫu nhiên: $dodai=6; $chuoi="QWERTYUIOPASDFGHJKLZXCVBNM0123456789"; $capt=""; for($i=1;$i<=$dodai;$i++) { $vitri=rand(0,35); $capt.=substr($chuoi,$vitri,1); } $_SESSION['captcha']=$capt; ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <form action="xuly.php" name="form1"id="form1" method="post">   <p>     <label for="textfield">Ho Ten:</label>     <input type="text" name="textfield" id="textfield">   </p>   <p>     <label for="textfield2">Mat Khau:</label>     <input type="text" name="textfield2" id="textfield2">   </p>   <p>     <label for="textfield3">Nhap ma xac ...

PHP#28MySQL#24 - GIỎ HÀNG 3 (xong)

Image
 //datbao.php <?php session_start(); if(!isset($_SESSION['giohang'])) $_SESSION['giohang']=array(); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <form id="f" name="form1" method="post" action="xuly.php">   <p>Đăng Ký Đặt Báo      <p>     <label for="loaibao">Loại báo:</label>     <select name="loaibao" id="loaibao">     <?php  include("connect.php"); $sql="select * from loaibao"; $kq=mysqli_query($link,$sql); while($d=mysqli_fetch_array($kq)) { ?>       <option value="<?php echo $d['mabao'];?>"><?php echo $d['tenbao'];?></option>        <?php }?>     </select>   </p>   <p>     <label for="soluong">Số lượng:</lab...

PHP#27MySQL#23 - GIỎ HÀNG 1+2

Image
PHẦN 2: //datbao.php <?php session_start(); if(!isset($_SESSION['giohang'])) $_SESSION['giohang']=array(); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <form id="f" name="form1" method="post" action="xuly.php">   <p>Đăng Ký Đặt Báo      <p>     <label for="loaibao">Loại báo:</label>     <select name="loaibao" id="loaibao">     <?php  include("connect.php"); $sql="select * from loaibao"; $kq=mysqli_query($link,$sql); while($d=mysqli_fetch_array($kq)) { ?>       <option value="<?php echo $d['mabao'];?>"><?php echo $d['tenbao'];?></option>        <?php }?>     </select>   </p>   <p>     <label for="soluong">Số lượng:...

PHP#26MySQL#22 - Hướng đối tượng Phần 3+4

Image
//lib.php <?php class tintuc{ private $link; //chứa mã kết nối //kết nối: function connect($host, $user, $pass, $db) { $this->link=@mysqli_connect($host,$user,$pass) or die("Không thể kết nối đến Server!"); mysqli_select_db($this->link,$db) or die("Không tồn tại DB này!"); mysqli_query($this->link,"set names 'utf8'"); } //Xây dựng hàm query: function query($sl) { $kq=mysqli_query($this->link,$sl) or die(mysqli_error()); return $kq; } //Xây dựng hàm fetch: function fetch($kq) { $d=mysqli_fetch_array($kq); return $d; } //Hàm num_rows: function num_rows($kq) { return mysqli_num_rows($kq); } //Hàm thể loại:Lấy các thể loại theo ngôn ngữ và trạng thái: function theloai($lang="vi", $anhien=1) { $sltl="select * from theloai where (lang='$lang' or '$lang'='') and (AnHien=$anhien or $anhien=-1) order by ThuTu ASC"; $...

PHP#25MySQL#21 - Hướng đối tượng Phần 1 - Xây dựng Hàm - Tin theo Loại - Class

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php  include("../connect.php"); //Xây dựng hàm: hàm nhận tham số đầu vào là id của 1 loại  và hàm trả về danh sách các tiêu đề tin thuộc loại tin đó: function tin_loai($idLT) { global $link; //biến toàn cục $sl="select * from tin where idLT=$idLT"; $kq=mysqli_query($link,$sl); while($d=mysqli_fetch_array($kq)) { echo $d['TieuDe']."<br/>"; } } echo "Các tin của loại tin có id=1: <br/>"; tin_loai(1); ?> </body> </html>

PHP#25MySQL#21 - Hướng đối tượng Phần 1 - Xây dựng Hàm

Image
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php  /*//Xây dựng hàm: function ten_ham(các_tham_số) { //Thân hàm: chứa các lệnh return giá trị; //có thể có hoặc không }*/ //Hàm không có return: function tinhtong($ts1, $ts2) { $tam=$ts1+$ts2; echo "Kết quả là: $tam <br/>"; } //Gọi hàm: tinhtong(15,7); tinhtong(23,48); //Hàm có return: function tinhtong2($ts1, $ts2) { $tam=$ts1+$ts2; return $tam; } //Gọi hàm : Đối với dạng có return: $kq1=tinhtong2(57,18); echo $kq1; ?> </body> </html>

PHP#24MySQL#20 Cookie, Xử lý, Ý kiến bạn đọc, bình luận

Image

PHP#23MySQL#19 - Đăng nhập, Session, Thoát user, Xử lý

Image

PHP#22MySQL#18 - Xóa, Sửa TIN & admin index (thể loại, loại tin)

//tin.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if(isset($_GET['lang'])) $lang=$_GET['lang'];   else $lang="vi"; ?> <form id="form1" name="form1" method="get" action="">   <p>     <label for="lang">Ngon ngu:</label>     <select name="lang" id="lang" onchange="form1.submit()">       <option value="vi">Viet</option>       <option value="en" <?php if($lang=="en") echo "selected";?>>English</option>     </select>   <...

PHP#21MySQL#17 - Upload, Xử lý, Thư viện, chèn Ckeditor

Image
//upload.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta  charset="utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="ckeditor/ckeditor.js"></script> </head> <body> <form action="process.php" method="post" enctype="multipart/form-data" name="form1" id="form1">   <p>     <label for="upImg">Chon anh:</label>     <input type="file" name="upImg" id="upImg" />   </p>   <p>     <label for="MoTa">Mo ta:</label>     <textarea name="MoTa" id="MoTa" cols="45" rows="5" class="ckeditor"></textarea>   <...

PHP#21MySQL#17 - tin_them.php, process.php - Thêm tin mới, Xử lý tin mới

Image
 //tin_them.php <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="ckeditor/ckeditor.js"></script> </head> <body> <?php include("../connect.php"); if(isset($_GET['lang'])) $lang=$_GET['lang']; else $lang='vi'; ?> <form id="form1" name="form1" method="get" action=""> <p> <label for="lang">Ngon ngu:</label> <select name="lang" id="lang" onchange="form1.submit();"> <option value="vi">Viet</option> <option value="en" <?php if($lang=='en') echo "selected='selected'";?>>Anh</option> </select> </p> <p> ...

PHP#20MySQL#16 - upfiles.php

Image
 <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <form method="post" enctype="multipart/form-data" name="form1" id="form1">   <input type="hidden" name="MAX_FILE_SIZE" value="102400"/>   <label for="upfile">File:</label>   <input type="file" name="upfile" id="upfile">   <input type="submit" name="submit" id="submit" value="Submit"> </form> <?php if(isset($_FILES['upfile'])) { //Thư mục để chứa file: $target="files/"; //lấy tên: $filename=basename($_FILES['upfile']['name']); //abc.jpg đang ở c:/hinh/abc.jpg $target=$target.$filename; //kiểm tra file đã có chưa: if(file_exists($target)) echo "File đã tồn tại!"; else echo ...

PHP#20MySQL#16 - tin.php : Lọc tin theo Ngôn ngữ, Thể loại, Loại & Phân trang

Image
//tin.php  <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> .ht{ font-weight: bold; color:#E80206; font-size:20px;} </style> </head> <body> <?php include("../connect.php");  if(isset($_GET['lang'])) $lang=$_GET['lang']; else $lang="vi"; ?> <form method="get" id="form1" name="form1" action="">   <p>     <label for="idTL">Ngôn ngữ:</label>     <select name="lang" id="lang" onChange="form1.submit();">       <option value="vi">Việt</option>       <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>     </select>   </p>   <p>     <label for="idTL">Thể loại:</label>     <select name=...

PHP#20MySQL#16 - Xóa LOẠI TIN

Image
//loaitin.php (phần Xóa) <!doctype html> <html> <head> <meta charset="utf-8"> <title>Loại Tin</title> </head> <body> <?php include("../connect.php"); if(isset($_GET['lang'])) $lang=$_GET['lang']; else $lang="vi"; ?> <form method="get" id="form1" name="form1">   <p>     <label for="loaitin">Chọn ngôn ngữ:</label>     <select name="lang" id="lang" onChange="form1.submit();">       <option value="vi">Việt</option>       <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>     </select>   </p>   <p>     <label for="theloai">Thể loại:</label>     <select name="theloai" id="theloai" onChange="form1.submit();"> <?php  ...

PHP#19MySQL#15 - Loại tin, Thêm, Sửa, Xử lý

Image
//connect.php <?php $link=@mysqli_connect("localhost","root","") or die("Không tìm thấy Sever"); mysqli_select_db($link,"tintuc") or die("Không tồn tại DB"); mysqli_query($link,"set names 'utf8'"); ?>

PHP#18MySQL#14 - Thêm, Xóa, Sửa, Lọc theo ngôn ngữ, lọc theo thể loại, loại

Image
  //theloai.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Thể Loại</title> </head> <body> <?php include("../connect.php"); if(isset($_GET['lang'])) $lang=$_GET['lang']; else $lang="vi"; ?> <form method="get" id="form1" name="form1">   <p>     <label for="select">Chọn ngôn ngữ:</label>     <select name="lang" id="lang" onChange="form1.submit();">       <option value="vi">Việt</option>       <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>     </select>   </p> </form> <table width="700" border="1" cellspacing="0" cellpadding="0">   <tbody>     <tr>       <th scope="col">Thứ tự</t...

PHP#17MySQL#13 - Trang xử lý THÊM dữ liệu (process.php) - Chuyển trang trong PHP: header("location:theloai.php");

<?php  include("../connect.php"); if(isset($_POST['themtl'])) { $sl="insert into theloai values(NULL,'{$_POST['lang']}', '{$_POST['TenTL']}', '{$_POST['TenTL_KhongDau']}', {$_POST['ThuTu']}, {$_POST['AnHien']})"; if(mysqli_query($link,$sl)) header("location:theloai.php"); else echo $sl; } ?>

PHP#17MySQL#13 - Admin/theloai_them.php - $_GET['lang']) sau đó selected ngôn ngữ

 <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php  if(isset($_GET['lang'])) $lang=$_GET['lang']; else $lang="vi"; ?> <form method="post" id="form1" name="form1" action="process.php" >   <p>     <label for="lang">Ngôn ngữ:</label>     <select name="lang" id="lang">       <option value="vi">Việt</option>       <option value="en" <?php if($lang=="en") echo "selected";?> >English</option>     </select>   </p>   <p>     <label for="ThuTu">Thứ tự:</label>     <input name="ThuTu" type="text" id="ThuTu" size="5">   </p>   <p>     <label for="TenTL">Tên TL:</label...

PHP#17MySQL#13 - Admin/theloai.php - Lọc thể loại theo ngôn ngữ, selected ngôn ngữ, chuyển trang kèm theo ngôn ngữ

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Thể Loại</title> </head> <body> <p> <?php  if(isset($_GET['lang'])) $lang=$_GET['lang']; else $lang="vi"; ?>  <form id="form1" name="form1" method="get" action="">   <label for="lang">Chọn ngôn ngữ:</label>   <select name="lang" id="lang" onChange="form1.submit();">     <option value="vi">Việt</option>     <option value="en" <?php if($lang=="en") echo "selected";?> >English</option>   </select>  </form> </p> <table width="700" border="1" cellspacing="0" cellpadding="0">   <tbody>     <tr>       <th scope="col">Thứ tự</th>       <th scope="col">Tê...

PHP#17MySQL#13 - tin cũ hơn

Image
//chitiettin.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php if(isset($_GET['idTin'])) { $idTin=$_GET['idTin']; include("connect.php"); $sl="select idLT, TieuDe, TomTat, Content from tin where idTin=$idTin"; $kq=mysqli_query($link,$sl); $d=mysqli_fetch_array($kq) ?> <h1 align="center"><?php echo $d['TieuDe'];?></h1> <div><?php echo $d['TomTat'];?></div> <div><?php echo $d['Content'];?></div> <?php }?> <p> các tin cũ hơn(lấy 5 tin cũ hơn và cùng loại tin với tin đang mở, sắp xếp từ mới đến cũ </p> <ul> <?php  $sltc="select * from tin where AnHien=1 and idLT={$d['idLT']} and idTin < $idTin order by idTin DESC limit 0,5"; $kqtc=mysqli_query($link,$sltc); while($dtc...

PHP#16MySQL#12 - index.php, include

Image
https://app.mediafire.com/fwx971t2bbggr  //index.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <link href="c2.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <div id="header"> </div>    <div id="thanhmenu"><?php include("menu.php");?></div>   <div id="main1">     <div id="main1_1"><?php include("tinnoibat.php");?></div> <div id="main1_2"><?php include("tinxemnhieu.php");?></div> <div id="main1_3">  </div> </div> <div id="quangcao"> </div> <div id="main2"> <div id="main2_1"> <?php  if(isset($_GET['key'])) { switch($_GET['key']...

PHP#15MySQL#11 chèn link, rót dữ liệu, phân trang

Image
//tinmoi.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> #tinmoi {width: 660px;} #tinmoi .tinmoinhat { width:330px; float:left; color:#336699; height: 175px; overflow: hidden; } #tinmoi .tinmoitieptheo { float:left; width:329px; height: 175px; overflow: hidden; white-space: nowrap; border-left: dotted 1px #030; } #tinmoi .theloai { font-size:18px; background-color:#003300; color:#FFF; padding-top:5px; padding-bottom:5px; clear:left } #tinmoi .theloai a { color:#9C0; text-decoration:none; margin-left:5px; font-size:16px;} #tinmoi .theloai a:hover{ color:#6CC; text-decoration:underline; } #tinmoi .tinmoinhat a { t...

PHP#14MySQL#10 - Slider (Chính thức làm web)

Image
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Featured Content Slider Using jQuery - Web Developer Plus Demos</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script type="text/javascript" src="jquery.min.js" ></script> <script type="text/javascript" src="jquery-ui.min.js" ></script> <script type="text/javascript"> $(document).ready(function(){ $("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 3000, true); }); </script> </head> <body> ...

PHP#14MySQL#10 - tintuc.sql - Menu (Chính thức làm web tin tức) tinxemnhieu.php , tinnoibat.php, tinmoi.php

Image
//tinxemnhieu.php <style type="text/css"> <!-- #tinxemnhieu { width: 250px; border: 1px solid #0099CC; overflow: hidden; white-space: nowrap; } #tinxemnhieu h4 { background-color: #0099CC; margin-top: 0px; margin-bottom: 0px; padding-top: 5px; padding-bottom: 5px; padding-left: 10px; color: #FFFF00; } #tinxemnhieu a { color: #CC3399; text-decoration: none; } #tinxemnhieu a:hover { color: #FFCC00; } #tinxemnhieu p { margin-top: 0px; margin-bottom: -1px; background-color: #FFFFCC; padding-top: 5px; padding-bottom: 5px; padding-left: 10px; border: 1px solid #0099CC; } --> </style> <div id="tinxemnhieu"> <h4>TIN XEM NHIỀU</h4> <?php $link=@mysqli_connect("localhost","root","") or die("Không tìm thấy Sever"); mysqli_select_db($link,"tintuc") or die("Không tồn tại DB"); mysqli_query($link,"set names 'utf8'"); $sl="select ...

PHP#13MySQL#9 - TabsMenu

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="60" colspan="3">&nbsp;</td> </tr> <tr> <td colspan="3" bgcolor="#FF9933"> <!--Links used to initiate the sub menus. Pass in the desired submenu index numbers (ie: 0, 1) --> <?php include("../connect.php"); $sl1="select idTL, TenTL from theloai"; $kq1=mysqli_query($link,$sl1); $i=0; while($d1=mysqli_fetch_array($kq1)) { if($i>0){echo ...