ทำไม javascript โปรแกรมไม่แจ้งข้อความว่าไม่ได้ใส่ข้อมูลครับ
คือผมใสภาษาจาวาสคลิ๊บ ถ้าไม่มีการใส่ username และ password จะมี box แจ้งว่าไม่ได้ใส่ username ถ้าไม่ใส่ password ก็จะแจ้งว่าไม่ได้ใส่ password ครับแต่รันโปรแกรม ไม่ได้แจ้งอะไรเลย ข้ามได้เฉยๆไปหน้า member.php แล้วไม่มีอะไรเกิดขึ้นหน้าว่างๆ
left_menu.php
<html>
<head>
<script Language="JavaScript">
var timerID = null;
var timerRunning = false;
function stopclock ()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime ()
{
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock ()
{
stopclock();
showtime();
}
</script>
<SCRIPT language=JavaScript>
<!--
function trim(str)
{
while (str.charAt(0) == ' ')
str = str.substring(1);
while (str.charAt(str.length - 1) == ' ')
str = str.substring(0, str.length - 1);
return str;
}
//-->
<!--
function chkValue()
{
txt = trim(document.regis.username.value)
if(txt.length < 2 ) {
alert("¡ÃسÒãÊè ª×èÍ-¹ÒÁÊ¡ØÅ ¤èÐ");
document.regis.username.focus();
return false;
}
txt = trim(document.regis.password.value)
if(txt.length < 2) {
alert("¡ÃسÒãÊè ª×èÍ-¹ÒÁÊ¡ØÅ ¤èÐ");
document.regis.password.focus();
return false;
}
}
return true;
}
//-->
</SCRIPT>
</head>
<body>
<form name="regis" action="../chapter19/member.php" method="post" onSubmit="return chkValue()" >
<table width="200" height="890" border=0 align="center" bgcolor="#6699CC" valign="top">
<tr>
<td width="194" height="20" align="center"><font face = "MS Sans Serif" color="#000000" size="2"><b> ª×èͼÙéãªé</b></font></td>
</tr>
<tr><td height="26" align="center"><input name="username" id="name" type="text" maxlength="20" size="15"></td>
</tr>
<tr>
<td height="20" align="center"><font face = "MS Sans Serif" color="#000000" size="2"><b> ÃËÑʼèÒ¹</b></font></td>
</tr>
<tr><td height="26" align="center"><input name="password" type="password" maxlength="20" size="15"></td>
</tr>
<tr><td height="28" colspan="2" align="center">
<input name="submit" type="submit" id="submit" value="ÅçÍ¡ÍÔ¹">
</tr>
<tr><td height="44" colspan="2" align="left"><font face = "MS Sans Serif" color="#ffffff" size="2"><br>
<img src="../images/ico_m.gif" border="0"> <b>ÂѧäÁèä´éà»ç¹ÊÁÒªÔ¡ ? ¤ÅÔê¡·Õè¹Õè </b></font></td></tr>
<tr><td height="18" colspan="2" align="left"><font face = "MS Sans Serif" color="#000000" size="2"><img src="../images/bullet1.gif" border="0"> <a class ="lmenu" href = "../chapter19/forgetpassword_form.php"> <b>Å×ÁÃËÑʼèÒ¹</b></a></font></td>
</tr><br>
<tr><td height="20" colspan="2" align="left"><font face = "MS Sans Serif" color="#000000" size="2"><img src="../images/bullet1.gif" border="0"> <a class ="lmenu" href ="../chapter19/register_form.php"> <b>ŧ·ÐàºÕ¹</b></a></font></td>
</tr>
<tr>
<td height="20" colspan="2" align="left"><font face = "MS Sans Serif" color="#000000" size="2"><b><img src="../images/bullet1.gif" border="0"> <a class ="lmenu" href="../chapter24/mailing.php">ÃѺ¢èÒÇÊÒâͧºÃÔÉÑ·</a></b></font></td>
<tr><td height="26" align="center">----------------------------------------------</td>
</tr>
<tr><td height="55"><img src =../images/bn_applyjob.gif></td>
</tr>
<tr><td height="55"><img src =../images/bn_chulapress.jpg></td>
</tr>
<tr><td height="55"><img src =../images/bn_form.jpg></td>
</tr>
<tr><td height="55"><img src =../images/bn_library.jpg></td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
<tr><td height="26"> </td>
</tr>
</table>
</form>
</body>
</html>
member.php
<?
session_start();
require_once("../include/connect_db.php");
require_once("../include/function.php");
require_once("../include/header.php");
if($username && $password)
{
if(login($username,$password,'ktpbook','users'))
{
$valid_user = $username;
session_register("valid_user");
}
else
{
header_html("à¡Ô´¢éͼԴ¾ÅÒ´");
echo "<tr><td><center><font face = \"MS Sans Serif\" color=\"#000000\" size=\"3\">¤Ø³äÁèÊÒÁÒö·Õè¨ÐÅçÍ¡ÍÔ¹ä´é ¡ÃسҵÃǨÊͺÍÕ¡¤ÃÑé§</font></center></td></tr>";
require_once("../include/footer.php");
exit;
}
require_once("../chapter19/home.php");
}
?>
funtion.php
<?
//================================================================================
function login($username,$password,$databasename,$tablename)
/*µÃǨÊͺ username ¡Ñº password ¡Ñº°Ò¹¢éÍÁÙÅ
¶éÒ¾ºãËé¤×¹¤èÒà»ç¹¨ÃÔ§ ËÒ¡äÁ辺ãËé¤×¹¤èÒà»ç¹à·ç¨
*/
{
//àª×èÍÁ⧰ҹ¢éÍÁÙÅ
$conn = connect_db($databasename);
if(!$conn)
return 0;
//µÃǨÊͺ username ÇèÒ«éӡѺ㹰ҹ¢éÍÁÙÅËÃ×ÍäÁè
$sql = "select * from $tablename where username='$username' and password=password('$password')";
$result = mysql_query($sql);
if(!$result)
return 0;
if(mysql_num_rows($result)>0)
return 1;
else
return 0;
}
//================================================================================
function select_cat($key)
{
$conn=connect_db("ktpbook");
if(!$conn)
echo "à¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é";
$sql="select * from categories where catid='$key' ";
$result = mysql_query($sql);
if(!$result)
return 0;
else
return $result;
}
function select_book($isbn)
{
$conn=connect_db("ktpbook");
if(!$conn)
echo "à¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é";
$sql="select * from books where isbn='$isbn' ";
$result = mysql_query($sql);
if(!$result)
return 0;
else
return $result;
}
//=================================================================================
/*¿Ñ§¡ìªÑ¹à¾ÔèÁÃÒ¡ÒÃ˹ѧÊ×Í*/
function insert_book($isbn,$author,$title,$price,$description,$picture,$publisher,$time,$page,$catid)
{
$con=connect_db("ktpbook");
if(!$con)
{
return "äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é ¡ÃسҾÂÒÂÒÁÍÕ¡¤ÃÑé§";
exit;
}
$sql = "select * from books where isbn='$isbn'";
$result = mysql_query($sql);
if(!$result)
return "¡ÃسҵÃǨ¤ÔÇÃÕ ÍÕ¡¤ÃÑé§ <br>";
if(mysql_num_rows($result)>0)
return "ª×èͧ͢¼Ùéãªé«éӡѺ㹰ҹ¢éÍÁÙÅ <br>";
$result = mysql_query("insert into books values ('$isbn','$author','$title',$price,'$description','$picture','$publisher','$time','$page',$catid)");
if(!$result)
return("äÁèÊÒÁÒöà¾ÔèÁÃÒ¡ÒÃ˹ѧÊ×Íä´é");
else
return true;
}
//=================================================================================
/*¿Ñ§¡ìªÑ¹ÅºÃÒ¡ÒÃ˹ѧÊ×Í*/
function delete_book($isbn)
{
$con=connect_db("ktpbook");
if(!$con)
return "äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é ¡ÃسҾÂÒÂÒÁÍÕ¡¤ÃÑé§";
$result = mysql_query("delete from books where isbn='$isbn'");
if(!$result)
return("äÁèÊÒÁÒöźÃÒ¡ÒÃ˹ѧÊ×Íä´é");
else
return true;
}
//=================================================================================
/*¿Ñ§¡ìªÑ¹¡ÒÃá¡éä¢ÃÒÂÅÐàÍÕ´˹ѧÊ×Í*/
function edit_book($oldisbn,$isbn,$author,$title,$price,$description,$picture,$publisher,$time,$page,$catid)
{
$con=connect_db("ktpbook");
if(!$con)
return "äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é ¡ÃسҾÂÒÂÒÁÍÕ¡¤ÃÑé§";
$sql="update books set isbn='$isbn' ,author='$author',title='$title' ,price=$price , description = '$description' , picture='$picture' , publisher='$publisher' ,time='$time' , page=$page , catid = $catid where isbn='$oldisbn' ";
$result = mysql_query($sql);
if(!$result)
return("äÁèÊÒÁÒöà¾ÔèÁÃÒ¡ÒÃ˹ѧÊ×Íä´é");
else
return true;
}
//=================================================================================
function insert_cat($catname)
{
$con=connect_db("ktpbook");
if(!$con)
{
return "äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é ¡ÃسҾÂÒÂÒÁÍÕ¡¤ÃÑé§";
exit;
}
$result = mysql_query("insert into categories(catname) values ('$catname')");
if(!$result)
return("äÁèÊÒÁÒöà¾ÔèÁÃÒ¡ÒÃËÁÇ´ËÁÙèä´é");
else
return true;
}
//=================================================================================
//á¡éä¢ËÁÇ´ËÁÙè˹ѧÊ×Í
function edit_cat($catid,$catname)
{
$con=connect_db("ktpbook");
if(!$con)
return "äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é ¡ÃسҾÂÒÂÒÁÍÕ¡¤ÃÑé§";
$sql="update categories set catname='$catname' where catid = $catid ";
$result = mysql_query($sql);
if(!$result)
return("äÁèÊÒÁÒöà¾ÔèÁÃÒ¡ÒÃ˹ѧÊ×Íä´é");
else
return true;
}
//=================================================================================
function delete_cat($catid)
{
$con=connect_db("ktpbook");
if(!$con)
return "äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é ¡ÃسҾÂÒÂÒÁÍÕ¡¤ÃÑé§";
$result = mysql_query("delete from categories where catid='$catid'");
if(!$result)
return("äÁèÊÒÁÒöźÃÒ¡ÒÃËÁÇ´ËÁÙèä´é");
else
return true;
}
//=================================================================================
/*¿Ñ§¡ìªÑ¹ÊÓËÃѺ¹Ó¢éÍÁÙÅã¹°Ò¹¢éÍÁÙÅà¡çºäÇéã¹ÍÐàÃÂì*/
function db_to_array($result)
{
$result_array=array();
for($count=0;$row=@mysql_fetch_array($result);$count++)
$result_array[$count]=$row;
return $result_array;
}
//=================================================================================
/*¿Ñ§¡ìªÑ¹¤Ó¹Ç¹ÃÒ¤Ò¡ÒÃÊÑ觫×éÍ*/
function calculate_price($cart)
{
$price = 0.0;
if(is_array($cart))
{
$conn = connect_db("ktpbook");
foreach($cart as $isbn => $qty)
{
$query = "select price from books where isbn='$isbn'";
$result = mysql_query($query);
if ($result)
{
$item_price = mysql_result($result, 0, "price");
$price +=$item_price*$qty;
}
}
}
return $price;
}
//=================================================================================
/*¿Ñ§¡ìªÑ¹¤Ó¹Ç³ÃÒ¡ÒÃÊÑ觫×éÍ*/
function calculate_items($cart)
{
// ¼ÅÃÇÁ¢Í§ÃÒ¡ÒÃÊÑ觫ÖéÍ
$items = 0;
if(is_array($cart))
{
foreach($cart as $isbn => $qty)
{
$items += $qty;
}
}
return $items;
}
//=================================================================================
//áÊ´§ÃÒ¡ÒÃÊÔ¹¤éÒ·ÕèàÅ×Í¡«×éÍ
function display_cart($cart,$change)
{
global $items;
global $total_price;
echo "<table border = 0 width = 100% cellspacing = 0 align=center>
<form action = ../chapter20/show_cart.php method = post>
<tr bgcolor=FFBBBB>
<th><font face=MS Sans Serif size=3>ª×èÍ˹ѧÊ×Í</font></th>
<th><font face=MS Sans Serif size=3>ª×èͼÙéáµè§</font></th>
<th><font face=MS Sans Serif size=3>ÃÒ¤Ò</font></th>
<th><font face=MS Sans Serif size=3>¨Ó¹Ç¹</font></th>
<th><font face=MS Sans Serif size=3>ÃÒ¤ÒÃÇÁ</font></th>
</tr>";
foreach ($cart as $isbn => $qty)
{
$book = get_book_details($isbn);
echo "<tr>";
echo "<td>";
echo "<a href = \"../chapter20/detailbook.php?isbn=".$isbn."\"><font face=\"MS Sans Serif\" size=2>".$book["title"]."</font></a></td>" ;
echo "<td><font face=\"MS Sans serif\" size=2>".$book["author"]."</font></td>";
echo "<td align = center><font face=\"MS Sans Serif\" size=2>".number_format($book["price"], 2) ."</font></td>";
echo "<td align = center>";
if ($change == true)
echo "<input type = text name = \"$isbn\" value = $qty size = 2>";
else
echo "<font face=\"MS Sans serif\" size=2>".$qty."</font>";
echo "</td><td align = right><font face=\"MS Sans Serif\" size=2>" .number_format($book["price"]*$qty,2). " ºÒ·</font></td></tr>\n";
}
// áÊ´§¼ÅÃÇÁ¢Í§ÃÒ¤Ò
echo "<tr bgcolor=#FFAAAA>
<th align = left colspan=3>¼ÅÃÇÁÃÒ¤ÒÊÔ¹¤éÒ·Ñé§ËÁ´</th>
<th align = center>$items</th>
<th align = right>".number_format($total_price, 2)." ºÒ·</th></tr>";
if($change == true)
{
echo "<tr>
<td colspan =4> </td>
<td align = center>
<input type = hidden name = new value =0 >
<input type = hidden name = save value = true>
<input type = submit value = \"ºÑ¹·Ö¡¡ÒÃà»ÅÕè¹á»Å§\">
</td>
<td> </td>
</tr>";
}
echo "</form></table>";
}
//=================================================================================
function checkout_form()
{
//áÊ´§ÃٻẺÊÓËÃѺ»é͹ÃÒÂÅÐàÍÕ´ÅÙ¡¤éÒ
?>
<br>
<table border = "0" width = "100%" cellspacing = "0" bgcolor="#FFEEEE" align="center">
<form action = "../chapter20/purchase.php" method = "post">
<tr><th colspan = "2" bgcolor="#FFBBBB">ÃÒÂÅÐàÍÕ´¢Í§ÅÙ¡¤éÒ</th></tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">ª×èÍ</font></th>
<td><input type = "text" name = "name" value = "" maxlength = "40" size = "30"></td>
</tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">¹ÒÁÊ¡ØÅ</font></th>
<td><input type = "text" name = "surname" value = "" maxlength = "20" size = "30"></td>
</tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">àºÍÃìâ·ÃÈѾ·ì </font></th>
<td><input type = "text" name = "phone" value = "" maxlength = "20" size = 20></td>
</tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">·ÕèÍÂÙè </font></th>
<td><input type = "text" name = "address" value = "" maxlength = "100" size = "40"></td>
</tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">ÍÓàÀÍ/ࢵ</font></th>
<td><input type = "text" name = "district" value = "" maxlength = "20" size = "20"></td>
</tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">¨Ñ§ËÇÑ´</font></th>
<td><input type = "text" name = "province" value = "" maxlength = "20" size = "20"></td>
</tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">ÃËÑÊä»ÃɳÕÂì</font></th>
<td><input type = "text" name = "zip" value = "" maxlength = "10" size = "10"></td>
</tr>
<tr>
<th align="left"><font face="Ms sans serif" size="3" style="margin: 2cm">»ÃÐà·È</font></th>
<td><input type = text name = "country" value = "" maxlength = "20" size = "20"></td>
</tr>
<tr>
<td colspan = "2" align = "center">
<font face="Ms Sans serif" size="2"><b>ËÒ¡µÃǨÊͺ¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇãËé¤ÅÔ¡·Õè»ØèÁ ÊÔé¹ÊØ´¡Òë×éÍ à¾×èÍ«×éÍÊÔ¹¤éÒ ËÃ×ͤÅÔ¡·Õè»ØèÁ àÅ×Í¡ÊÔ¹¤éÒµèÍ à¾×èÍàÅ×Í¡«×éÍËÃ×Íá¡éä¢ÃÒ¡ÒÃÊÑ觫×éÍ</b></font>
</td>
</tr>
<tr>
<td align="center"><input type="submit" value="ÊÔé¹ÊØ´¡Òë×éÍ"></td>
</form>
<td align="center"><form action="../chapter19/home.php" method="post"><input type="submit" value="àÅ×Í¡ÊÔ¹¤éÒµèÍ"></form></td>
</tr>
</table>
<?
}
//=================================================================================
function display_shipping($shipping)
{
// áÊ´§ÃÒ¤ÒÃÇÁ¤èÒ¢¹Êè§
global $total_price;
global $items;
?>
<table border = 0 width = "100%" cellspacing = "0" align="center">
<tr><td align = left><font face="MS Sans Serif" size=3>¤èҨѴÊè§</font></td>
<td align = right><font face="MS Sans Serif" size=3><?=number_format($shipping, 2); ?> ºÒ·</font></td></tr>
<tr bgcolor="#FF7777"><th align = "left"><font face=MS Sans Serif size=3>ÃÇÁÃÒ¤Ò·Ñé§ËÁ´</font></th>
<th align = "right"><font face=MS Sans Serif size=3><?=number_format($shipping+$total_price, 2); ?> ºÒ·</font></th>
</tr>
</table><br>
<?
}
//=============================================================================
function card_form($name)
{
//¨ÍÀÒ¾ÊÓËÃѺ»é͹ÃÒÂÅÐàÍÕ´¢Í§à¤Ã´Ôµ¡ÒÃì´ áÊ´§ÇÔ¸Õ¡ÒêÓÃÐà§Ô¹¼èÒ¹·Ò§ºÑµÃ àÍ·ÕàÍçÁ
extract($name);
?>
<form id="form1" name="form1" method="post" action="../chapter20/process.php">
<table width="704" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF3300" bgcolor="#FFFFCC">
<tr>
<td width="700"><table width="629" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><span class="style1">ÇÔ¸Õ¡ÒêÓÃÐà§Ô¹</span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>ªÓÃÐà§Ô¹à¢éҺѭªÕ (¡ÃسÒàÅ×Í¡ºÑ­ªÕãËé¶Ù¡µéͧ) <span class="style3">** </span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><label>
<input name="radiobutton" type="radio" value="radiobutton" />
(360-2-14988-4) ¸¹Ò¤Òà ä·Â¾Ò³ÔªÂì (ÊÒ¢Ò ÂèÍ¿ÔÇà¨ÍÃì¾ÒÃì¤ ÃѧÊÔµ) </label></td>
</tr>
<tr>
<td><label>
<input name="radiobutton" type="radio" value="radiobutton" />
(148-1-34037-9) ¸¹Ò¤Òà ¡Ãاä·Â (ÊÒ¢Ò ÃѧÊÔµ-¹¤Ã¹Ò¡ ¤Åͧ 4)
</label></td>
</tr>
<tr>
<td><label>
<input name="radiobutton" type="radio" value="radiobutton" />
(026-0-37230-5) ¸¹Ò¤Òà ¡Ãا෾ (ÊÒ¢Ò ÂèÍ¿ÔÇà¨ÍÃì¾ÒÃì¤ ÃѧÊÔµ)</label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>àÃÒãªé¡ÒõÃǨÊͺà§Ô¹¼èÒ¹ÃкºÍÔ¹àµÍÃìà¹çµ ·èÒ¹äÁèÊÒÁÒöáͺÍéÒ§¡ÒêÓÃÐà§Ô¹·ÕèäÁèà»ç¹¨ÃÔ§ä´éáµèÍÂèҧ㴠</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>¨Ó¹Ç¹à§Ô¹ <span class="style3">*</span> <label>
<input type="text" name="textfield" />
ºÒ· </label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>ªÓÃÐàÁ×èÍÇѹ·Õè <span class="style3">* </span> <label>
<input type="text" name="textfield2" />
(àªè¹ 12 Á¡ÃÒ¤Á 2551) </label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>àÁ×èÍàÇÅÒ <span class="style3">* </span> <label>
<input type="text" name="textfield3" />
(àªè¹ 12.30 ¹. »ÃÐÁÒ³àÍÒ¤ÃѺ)</label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>ËÁÒÂà˵ØÍ×è¹ æ <label>
<textarea name="textfield4" cols="40" rows="6"></textarea>
</label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><div align="center">¤ÅÔê¡·Õè»ØèÁ <span class="style4">ÊÔé¹ÊØ´¡ÒÃÊÑ觫×éÍ</span> à¾×èÍÊÑ觫×éÍÊÔ¹¤éÒ ËÃ×ͤÅÔê¡»ØèÁ <span class="style6">ÊÑ觫×éÍÊÔ¹¤éÒµèÍ</span> à¾×èÍàÅ×Í¡«×éÍÊÔ¹¤éÒµèÍ </div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="ÊÔé¹ÊØ´¡ÒÃÊÑ觫×éÍ" />
</div></td>
</tr>
<tr>
<td><label></label></td>
</tr>
<form id="form1" name="form1" method="post" action="../chapter20/process.php">
<tr>
<td><label>
<div align="center">
<input type="submit" name="Submit2" value="ÊÑ觫×éÍÊÔ¹¤éÒµèÍ." />
</div>
</label></td>
</tr></form>
<tr>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<?
}
//=============================================================================
//¿Ñ§¡ìªÑ¹ÊÓËÃѺà¾ÔèÁÃÒ¡ÒÃÊÑ觫×éÍ
function insert_order($order_details)
{
global $total_price;
global $cart;
extract($order_details);
//㹡óշÕèÃÒÂÅÐàÍÕ´¢Í§¼ÙéÊ觡Ѻ¼Ùé«×éÍàËÁ×͹¡Ñ¹
if(!$ship_name&&!$ship_surname&&!$ship_address&&!$ship_phone&&!$ship_district&&!$ship_province&&!$ship_zip&&!$ship_country)
{
$ship_name = $name;
$ship_surname = $surname;
$ship_address = $address;
$ship_phone =$phone;
$ship_district = $district;
$ship_province = $province;
$ship_zip = $zip;
$ship_country = $country;
}
$conn = connect_db("order_book");
//µÃǨÊͺÃÒÂÅÐàÍÕ´¢Í§ÅÙ¡¤éÒ
$sql = "select customerid from customer where name = '$name' and surname = '$surname' and address = '$address' and district = '$district' and province = '$province' and zip = '$zip' and country = '$country' and phone='$phone' ";
$result = mysql_query($sql);
if(!$result)
return "¡ÃسҵÃǨ¤ÔÇÃÕ ÍÕ¡¤ÃÑé§ <br>";
if(mysql_num_rows($result)>0)
{
$customer_id = mysql_result($result, 0, "customerid");
}
else
{
$sql = "insert into customer(name,surname,address,district,province,zip,country,phone) values ( '$name','$surname','$address','$district','$province','$zip','$country','$phone')";
$result = mysql_query($sql);
if (!$result)
return false;
}
$sql = "select customerid from customer where name = '$name' and surname = '$surname' and address = '$address' and district = '$district' and province = '$province' and zip = '$zip' and country = '$country' and phone='$phone'";
$result = mysql_query($sql);
if(!$result)
return "¡ÃسҵÃǨ¤ÔÇÃÕ ÍÕ¡¤ÃÑé§ <br>";
if(mysql_num_rows($result)>0)
$customerid = mysql_result($result, 0, "customerid");
else
return false;
$date = date("Y-m-d");
$sql = "insert into orders values
('', $customerid, $total_price, '$date', '$ship_name','$ship_surname',
'$ship_address','$ship_district','$ship_province','$ship_zip',
'$ship_country','$ship_phone')";
$result = mysql_query($sql);
if (!$result)
return false;
$sql = "select orderid from orders where customerid = $customerid and amount > $total_price-.001 and amount < $total_price+.001 and date = '$date' and ship_name = '$ship_name' and ship_surname = '$ship_surname' and ship_address = '$ship_address' and ship_district = '$ship_district' and ship_province = '$ship_province' and ship_zip = '$ship_zip' and ship_country = '$ship_country' and ship_phone ='$ship_phone'";
$result = mysql_query($sql);
if(mysql_num_rows($result)>0)
$orderid = mysql_result($result, 0, "orderid");
else
return false;
// »é͹ÃÒÂÅÐàÍÕ´¢Í§Ë¹Ñ§Ê×ÍáµèÅÐàÅèÁ
foreach ($cart as $isbn => $qty)
{
$book = get_book_details($isbn);
$price = $book["price"];
$conn = connect_db("order_book");
$sql="insert into order_items values ($orderid,'$isbn',$price,$qty)";
$result = mysql_query($sql);
if(!$result)
return false;
}
return $orderid;
}
//=============================================================================
function get_book_details($isbn)
{
if (!$isbn || $isbn=="")
return false;
$con=connect_db("ktpbook");
$query = "select * from books where isbn='$isbn'";
$result = mysql_query($query);
if (!$result)
return false;
$result = mysql_fetch_array($result);
return $result;
}
//=================================================================================
function process_card($detailcart)
{
extract($detailcart); if($card_name&&$card_type&&$card_number&&$card_code&&$card_month&&$card_year)
return true;
else
return false;
}
function ship_cost()
{
return 50;
}
//=================================================================================
function register($username,$password,$answer,$email)
{
$con=connect_db("ktpbook");
if(!$con)
return "äÁèÊÒÁÒöµÔ´µè͡Ѻ°Ò¹¢éÍÁÙÅä´é ¡ÃسҾÂÒÂÒÁÍÕ¡¤ÃÑé§";
$sql = "select * from users where username='$username'";
$result = mysql_query($sql);
if(!$result)
return "¡ÃسҵÃǨ¤ÔÇÃÕ ÍÕ¡¤ÃÑé§ <br>";
if(mysql_num_rows($result)>0)
return "ª×èͧ͢¼Ùéãªé«éӡѺ㹰ҹ¢éÍÁÙÅ <br>";
$result = mysql_query("insert into users values ('$username',password('$password'),'$answer','$email')");
if(!$result)
return("äÁèÊÒÁÒöŧ·ÐàºÕ¹ä´é");
else
return true;
}
//=============================================================================
function Tag : - - - -
Date :
22 พ.ย. 2551 15:40:47
By :
badboy2
View :
901
Reply :
1
ทำไม txt ไม่ประกาศตัวแปลล่ะครับ
Date :
22 พ.ย. 2551 20:28:57
By :
เอี่ยว
Load balance : Server 03