Skip to main content

Posts

PHP#31MySQL#27 - Ajax2

//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

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

//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 n...

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

 //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

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

//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"; $k...

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>