佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1088|回复: 12

php code 的问题

[复制链接]
发表于 3-5-2012 09:45 PM | 显示全部楼层 |阅读模式
本帖最后由 h@@ 于 3-5-2012 09:47 PM 编辑

我现在想做一个系统是关于学校的。我已经做了course的page,在里面有关于course的东西,包括学费。现在我要做一个payment的page。要付的钱就是course的学费,我已经做到了fetch那个course的学费去payment那边了,不过我要做fullpayment和installment的。installment会分四次来还。我想要选了installment就会马上换了,不要submit了才换的。请问要怎么写啊?刚学php不久。都是网上学的。希望可以帮帮忙。谢谢。payment.php
  1. <?php
  2. session_start();
  3. include("connect.php");
  4. ?>
  5. <html>
  6. <head><title>Payment</title>
  7. <script src="AJAX.js"></script>
  8. <script language="Javascript">     
  9. function validate_length(field)
  10. {
  11.   with(field)
  12.   {
  13.         if(value.length == 0)
  14.         {
  15.            alert("Cannot be empty !"); return false;
  16.         }else return true;
  17.   }
  18. }
  19. function validate_form(thisform)
  20. {
  21.   with (thisform)
  22.   {
  23.      if (validate_length(TraineeID) == false)
  24.       {
  25.             TraineeID.focus(); return false;
  26.       }
  27.   }
  28. }
  29. function getCookie (NameOfCookie)  {
  30.   if (document.cookie.length > 0)  {
  31.   begin = document.cookie.indexOf (NameOfCookie+"=");
  32.   if (begin !=-1)  {
  33.       begin += NameOfCookie.length+1;
  34.       end = document.cookie.indexOf (";", begin);
  35.       if (end ==-1) end = document.cookie.length;
  36.         return unescape(document.cookie.substring(begin, end));
  37.       }
  38.   }
  39.   return null;
  40. }

  41. function setCookie (NameOfCookie, value, expiredays)  {
  42. var ExpireDate = new Date ();
  43. ExpireDate.setTime (ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
  44.    
  45.      document.cookie = NameOfCookie + "=" + escape(value) +
  46.      ((expiredays == null) ? " " : "; expires=" + ExpireDate.toGMTString());
  47. }


  48. function DoTheCookieStuff()
  49. {
  50.       username=document.myform.TraineeID.value;
  51.       setCookie('username', username, 365);

  52. }
  53. function confirmation() {
  54.         var answer = confirm("Quit Payment?")
  55.         if (answer){
  56.                 window.location = "welcome.php";
  57.         }
  58.         else{
  59.                
  60.         }
  61. }
  62. </script>
  63. </head>
  64. <body>
  65. <center><h1>Payment</h1></center>
  66. <form name="myform" action="addpayment.php" onsubmit="return validate_form(this,DoTheCookieStuff())" method="post">
  67. <br>Payment ID:
  68.         <?php
  69.                 //Increment for the ID

  70.                
  71.                 $queryP = "SELECT PaymentID FROM paymentdetail ORDER BY PaymentID DESC LIMIT 1";
  72.                 $resultP = $db->query($queryP);
  73.                
  74.                 $rowP = $resultP->fetch_assoc();
  75.                 $PaymentID = $rowP["PaymentID"];
  76.                 list($one[0],$one[1]) = explode('P',$PaymentID);                //seperate the inventoryID code
  77.                 $index = ++$one[1];
  78.                 $number = $index;
  79.                
  80.                 if($index < 10)
  81.                 {
  82.                         $index = "P000".$index;
  83.                 }
  84.                 else if($index < 100)
  85.                 {
  86.                         $index = "P00".$index;
  87.                 }
  88.                 else if ($index < 1000)
  89.                 {
  90.                         $index = "P0".$index;
  91.                 }
  92.                 else if($index < 10000)
  93.                 {
  94.                         $index = "P".$index;
  95.                 }
  96.                
  97.                 echo "<input type='hidden' name='PaymentID' value='".$index."'>".$index;
  98.                 ?></br>
  99. <br>Trainee ID :<select id='TraineeID' name = 'TraineeID' onclick="showAmount(this.value);">
  100. <?php
  101. $host="localhost"; // Host name
  102. $username="root"; // Mysql username
  103. $password=""; // Mysql password
  104. $db_name="pratice"; // Database name
  105. $tbl_name="registration"; // Table name

  106. // Connect to server and select databse.
  107. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  108. mysql_select_db("$db_name")or die("cannot select DB");

  109. $res = mysql_query("SELECT TraineeID FROM registration ORDER BY TraineeID")
  110. or die("Invalid query: " . mysql_query());
  111. echo '<option value=""></option>';
  112. while ($row = mysql_fetch_assoc($res)) {
  113. $TraineeID = $row['TraineeID'];
  114. echo "<option value='$TraineeID'>$TraineeID</option>";
  115. }
  116. ?>
  117. </select></br>
  118. <br>Payment Type :<select id = 'PaymentType' name = 'PaymentType'>
  119.         <option value='FullPayment'>Full Payment</option>
  120.         <option value='Installment'>Installment</option>
  121.                 </select></br>

  122. <br>Payment Method : <input type="radio" name="PaymentMethod" value="Cash">Cash
  123.         <input type="radio" name="PaymentMethod" value="Credit Card" checked>Credit Card</br>                                 
  124. <br><div id="Amount">Amount:
  125. </div></br>
  126. <div style="text-align: center; width: 50% margin: 0 auto;">
  127. <br><input type="submit" name="submit" value="Submit">
  128. <input type="button" onclick="confirmation()" value="Cancel">
  129. </div>
  130. </form>
  131. </body></html>

复制代码

AJAX.js
  1. function showAmount(str)
  2. {
  3. if (str=="")
  4.   {
  5.   document.getElementById("Amount").innerHTML="";
  6.   return;
  7.   }
  8. if (window.XMLHttpRequest)
  9.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  10.   xmlhttp=new XMLHttpRequest();
  11.   }
  12. else
  13.   {// code for IE6, IE5
  14.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  15.   }
  16. xmlhttp.onreadystatechange=function()
  17.   {
  18.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  19.     {
  20.     document.getElementById("Amount").innerHTML=xmlhttp.responseText;
  21.     }
  22.   }
  23. xmlhttp.open("GET","getamount.php?TraineeID="+str,true);
  24. xmlhttp.send();
  25. }
复制代码



getamount.php
  1. <?php
  2. $TraineeID=$_GET["TraineeID"];
  3. $con = mysql_connect('localhost', 'root', '');
  4. if (!$con)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }

  8. mysql_select_db("pratice", $con);
  9. $sql="SELECT Fees FROM course,registration WHERE course.CourseName=registration.CourseName And registration.TraineeID = '".$TraineeID."'";
  10. $result = mysql_query($sql);
  11. echo "Amount:SGD[        DISCUZ_CODE_2        ]quot;;
  12. while($row=mysql_fetch_array($result)){
  13. $Amount=$row['Fees'];
  14. echo "$Amount";
  15. }
  16. echo "<input type='hidden' name='Amount' id='Amount' value='".$Amount."'/>";
  17. mysql_close($con);
  18. ?>
复制代码
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 3-5-2012 10:46 PM | 显示全部楼层
没人会吗?
回复

使用道具 举报

发表于 3-5-2012 11:13 PM | 显示全部楼层
回复 1# h@@



   
  1. <script type="text/javascript">
  2. function changePayment(str)
  3. {

  4. if (window.XMLHttpRequest)
  5.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  6.   xmlhttp=new XMLHttpRequest();
  7.   }
  8. else
  9.   {// code for IE6, IE5
  10.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  11.   }
  12. xmlhttp.onreadystatechange=function()
  13.   {
  14.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  15.     {
  16.     document.getElementById("paymentMethod").innerHTML=xmlhttp.responseText;
  17.     }
  18.   }
  19. xmlhttp.open("GET","changePay.php?loc="+str,true);
  20. xmlhttp.send();
  21. }
  22. </script>
复制代码


  1. <select name="paymentselect" onchange="changePayment(this.value)">
  2.                 <option value="fullpayment" >fullpayment</option>
  3.                 <option value="installment">installment</option>
  4.                </select>
复制代码


  1. <div id="paymentMethod" style="height: auto;" ></div>
复制代码



这个是一部分的code,自己去研究
回复

使用道具 举报

 楼主| 发表于 4-5-2012 12:18 AM | 显示全部楼层
本帖最后由 h@@ 于 4-5-2012 12:22 AM 编辑

类似这样的我有试过。。但是我在changepay.php那里出了问题。在sql那里我不知要写什么。我之前是写select fees from course.不过显示出来的是全部的fees。我只要traineeid选的那个fees。过后写了和getamount一样的sql,但是不知道怎样get traineeid。因为有两个values,不懂get。谢谢帮忙。
  1. <?php
  2. $PaymentType=$_GET["PaymentType"];
  3. $con = mysql_connect('localhost', 'root', '');
  4. if (!$con)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }

  8. mysql_select_db("pratice", $con);
  9. $sql="SELECT Fees FROM course";
  10. $result = mysql_query($sql);
  11. echo "Amount:SGD$";
  12. while($row=mysql_fetch_array($result)){
  13. if ($PaymentType=='Installment')
  14. {
  15. $Amount=$row['Fees']/4;
  16. echo "$Amount";
  17. }
  18. else if ($PaymentType=='FullPayment')
  19. {
  20. $Amount=$row['Fees'];
  21. echo "$Amount";
  22. }
  23. }
  24. mysql_close($con);
  25. ?>
复制代码


这是我之前试的code
回复

使用道具 举报

发表于 4-5-2012 09:39 AM | 显示全部楼层
回复 4# h@@

就pass user 选的traineeid 过去那一页咯。
回复

使用道具 举报

 楼主| 发表于 4-5-2012 10:04 PM | 显示全部楼层
要怎样啊?我想过,不过一直在网上找不到sample。
回复

使用道具 举报

Follow Us
发表于 4-5-2012 11:14 PM | 显示全部楼层
在changePayment(str) get user select 的 traineeid

  1. xmlhttp.open("GET","changePay.php?loc="+str,true);
复制代码

在上面这个pass过去"changePay.php?loc="+str+"&traineeid ="+traineeid
回复

使用道具 举报

发表于 4-5-2012 11:16 PM | 显示全部楼层
我这个是比较简单的。还有,如果要回复别人的贴,在那个人的贴下面按回复,别人才能知道你在回复他
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 5-5-2012 12:43 AM | 显示全部楼层
回复 7# leon_lcl

哦。。好的。谢谢。我去试试。
回复

使用道具 举报

 楼主| 发表于 5-5-2012 10:39 PM | 显示全部楼层
回复 7# leon_lcl

  1. function changePayment(str)
  2. {

  3. if (window.XMLHttpRequest)
  4.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  5.   xmlhttp=new XMLHttpRequest();
  6.   }
  7. else
  8.   {// code for IE6, IE5
  9.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  10.   }
  11. xmlhttp.onreadystatechange=function()
  12.   {
  13.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  14.     {
  15.     document.getElementById("paymentMethod").innerHTML=xmlhttp.responseText;
  16.     }
  17. xmlhttp.open("GET","changePay.php?PaymentType="+str+"&TraineeID ="+TraineeID,true);
  18.   }
  19. xmlhttp.send();
  20. }
复制代码

   
  1. <?php
  2. $PaymentType=$_GET["PaymentType"];
  3. $TraineeID_GET["TraineeID"];
  4. $con = mysql_connect('localhost', 'root', '');
  5. if (!$con)
  6.   {
  7.   die('Could not connect: ' . mysql_error());
  8.   }

  9. mysql_select_db("pratice", $con);
  10. $sql="SELECT Fees FROM course,registration WHERE course.CourseName=registration.CourseName And registration.TraineeID = '".$TraineeID."'";
  11. $result = mysql_query($sql);
  12. echo "Amount:SGD$";
  13. while($row=mysql_fetch_array($result)){
  14. if ($PaymentType=='Installment')
  15. {
  16. $Amount=$row['Fees']/4;
  17. echo "$Amount";
  18. }
  19. else if ($PaymentType=='FullPayment')
  20. {
  21. $Amount=$row['Fees'];
  22. echo "$Amount";
  23. }
  24. }
  25. mysql_close($con);
  26. ?>
复制代码

还是做不到,是不是哪里出问题了?
回复

使用道具 举报

发表于 5-5-2012 10:52 PM | 显示全部楼层
回复 10# h@@
你的TraineeID在function changePayment(str)都没有拿到value,怎样做到?拿value不是酱直接打他的id拿的
回复

使用道具 举报

 楼主| 发表于 5-5-2012 11:09 PM | 显示全部楼层
回复 11# leon_lcl

  1. function changePayment(str,TraineeID)
  2. {

  3. if (window.XMLHttpRequest)
  4.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  5.   xmlhttp=new XMLHttpRequest();
  6.   }
  7. else
  8.   {// code for IE6, IE5
  9.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  10.   }
  11. xmlhttp.onreadystatechange=function()
  12.   {
  13.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  14.     {
  15.     document.getElementById("paymentMethod").innerHTML=xmlhttp.responseText;
  16.     }
  17. xmlhttp.open("GET","changePay.php?PaymentType="+str+"&TraineeID ="+TraineeID,true);
  18.   }
  19. xmlhttp.send();
  20. }
复制代码

   是这样吗?不好意思啊,我都是网上学的。有些东西不是很了解。
回复

使用道具 举报

发表于 5-5-2012 11:23 PM | 显示全部楼层
回复 12# h@@

试看看 document.getElementById("TraineeID").value
不过从你的
  1. $res = mysql_query("SELECT TraineeID FROM registration ORDER BY TraineeID")
  2. or die("Invalid query: " . mysql_query());
  3. echo '<option value=""></option>';
  4. while ($row = mysql_fetch_assoc($res)) {
  5. $TraineeID = $row['TraineeID'];
  6. echo "<option value='$TraineeID'>$TraineeID</option>";
复制代码

你要validate user 有选到TraineeID
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 26-10-2025 08:00 PM , Processed in 0.362719 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表