|
查看: 1088|回复: 12
|
php code 的问题
[复制链接]
|
|
|
本帖最后由 h@@ 于 3-5-2012 09:47 PM 编辑
我现在想做一个系统是关于学校的。我已经做了course的page,在里面有关于course的东西,包括学费。现在我要做一个payment的page。要付的钱就是course的学费,我已经做到了fetch那个course的学费去payment那边了,不过我要做fullpayment和installment的。installment会分四次来还。我想要选了installment就会马上换了,不要submit了才换的。请问要怎么写啊?刚学php不久。都是网上学的。希望可以帮帮忙。谢谢。payment.php
- <?php
- session_start();
- include("connect.php");
- ?>
- <html>
- <head><title>Payment</title>
- <script src="AJAX.js"></script>
- <script language="Javascript">
- function validate_length(field)
- {
- with(field)
- {
- if(value.length == 0)
- {
- alert("Cannot be empty !"); return false;
- }else return true;
- }
- }
- function validate_form(thisform)
- {
- with (thisform)
- {
- if (validate_length(TraineeID) == false)
- {
- TraineeID.focus(); return false;
- }
- }
- }
- function getCookie (NameOfCookie) {
- if (document.cookie.length > 0) {
- begin = document.cookie.indexOf (NameOfCookie+"=");
- if (begin !=-1) {
- begin += NameOfCookie.length+1;
- end = document.cookie.indexOf (";", begin);
- if (end ==-1) end = document.cookie.length;
- return unescape(document.cookie.substring(begin, end));
- }
- }
- return null;
- }
-
- function setCookie (NameOfCookie, value, expiredays) {
- var ExpireDate = new Date ();
- ExpireDate.setTime (ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
-
- document.cookie = NameOfCookie + "=" + escape(value) +
- ((expiredays == null) ? " " : "; expires=" + ExpireDate.toGMTString());
- }
-
- function DoTheCookieStuff()
- {
- username=document.myform.TraineeID.value;
- setCookie('username', username, 365);
-
- }
- function confirmation() {
- var answer = confirm("Quit Payment?")
- if (answer){
- window.location = "welcome.php";
- }
- else{
-
- }
- }
- </script>
- </head>
- <body>
- <center><h1>Payment</h1></center>
- <form name="myform" action="addpayment.php" onsubmit="return validate_form(this,DoTheCookieStuff())" method="post">
- <br>Payment ID:
- <?php
- //Increment for the ID
-
- $queryP = "SELECT PaymentID FROM paymentdetail ORDER BY PaymentID DESC LIMIT 1";
- $resultP = $db->query($queryP);
-
- $rowP = $resultP->fetch_assoc();
- $PaymentID = $rowP["PaymentID"];
- list($one[0],$one[1]) = explode('P',$PaymentID); //seperate the inventoryID code
- $index = ++$one[1];
- $number = $index;
-
- if($index < 10)
- {
- $index = "P000".$index;
- }
- else if($index < 100)
- {
- $index = "P00".$index;
- }
- else if ($index < 1000)
- {
- $index = "P0".$index;
- }
- else if($index < 10000)
- {
- $index = "P".$index;
- }
-
- echo "<input type='hidden' name='PaymentID' value='".$index."'>".$index;
- ?></br>
- <br>Trainee ID :<select id='TraineeID' name = 'TraineeID' onclick="showAmount(this.value);">
- <?php
- $host="localhost"; // Host name
- $username="root"; // Mysql username
- $password=""; // Mysql password
- $db_name="pratice"; // Database name
- $tbl_name="registration"; // Table name
- // Connect to server and select databse.
- mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- $res = mysql_query("SELECT TraineeID FROM registration ORDER BY TraineeID")
- or die("Invalid query: " . mysql_query());
- echo '<option value=""></option>';
- while ($row = mysql_fetch_assoc($res)) {
- $TraineeID = $row['TraineeID'];
- echo "<option value='$TraineeID'>$TraineeID</option>";
- }
- ?>
- </select></br>
- <br>Payment Type :<select id = 'PaymentType' name = 'PaymentType'>
- <option value='FullPayment'>Full Payment</option>
- <option value='Installment'>Installment</option>
- </select></br>
- <br>Payment Method : <input type="radio" name="PaymentMethod" value="Cash">Cash
- <input type="radio" name="PaymentMethod" value="Credit Card" checked>Credit Card</br>
- <br><div id="Amount">Amount:
- </div></br>
- <div style="text-align: center; width: 50% margin: 0 auto;">
- <br><input type="submit" name="submit" value="Submit">
- <input type="button" onclick="confirmation()" value="Cancel">
- </div>
- </form>
- </body></html>
-
复制代码
AJAX.js
- function showAmount(str)
- {
- if (str=="")
- {
- document.getElementById("Amount").innerHTML="";
- return;
- }
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("Amount").innerHTML=xmlhttp.responseText;
- }
- }
- xmlhttp.open("GET","getamount.php?TraineeID="+str,true);
- xmlhttp.send();
- }
复制代码
getamount.php
- <?php
- $TraineeID=$_GET["TraineeID"];
- $con = mysql_connect('localhost', 'root', '');
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("pratice", $con);
- $sql="SELECT Fees FROM course,registration WHERE course.CourseName=registration.CourseName And registration.TraineeID = '".$TraineeID."'";
- $result = mysql_query($sql);
- echo "Amount:SGD[ DISCUZ_CODE_2 ]quot;;
- while($row=mysql_fetch_array($result)){
- $Amount=$row['Fees'];
- echo "$Amount";
- }
- echo "<input type='hidden' name='Amount' id='Amount' value='".$Amount."'/>";
- mysql_close($con);
- ?>
复制代码 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 3-5-2012 10:46 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 3-5-2012 11:13 PM
|
显示全部楼层
回复 1# h@@
- <script type="text/javascript">
- function changePayment(str)
- {
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("paymentMethod").innerHTML=xmlhttp.responseText;
- }
- }
- xmlhttp.open("GET","changePay.php?loc="+str,true);
- xmlhttp.send();
- }
- </script>
复制代码
- <select name="paymentselect" onchange="changePayment(this.value)">
- <option value="fullpayment" >fullpayment</option>
- <option value="installment">installment</option>
- </select>
复制代码
- <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。谢谢帮忙。- <?php
- $PaymentType=$_GET["PaymentType"];
- $con = mysql_connect('localhost', 'root', '');
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("pratice", $con);
- $sql="SELECT Fees FROM course";
- $result = mysql_query($sql);
- echo "Amount:SGD$";
- while($row=mysql_fetch_array($result)){
- if ($PaymentType=='Installment')
- {
- $Amount=$row['Fees']/4;
- echo "$Amount";
- }
- else if ($PaymentType=='FullPayment')
- {
- $Amount=$row['Fees'];
- echo "$Amount";
- }
- }
- mysql_close($con);
- ?>
复制代码
这是我之前试的code |
|
|
|
|
|
|
|
|
|
|
发表于 4-5-2012 09:39 AM
|
显示全部楼层
回复 4# h@@
就pass user 选的traineeid 过去那一页咯。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 4-5-2012 10:04 PM
|
显示全部楼层
|
要怎样啊?我想过,不过一直在网上找不到sample。 |
|
|
|
|
|
|
|
|
|
|
发表于 4-5-2012 11:14 PM
|
显示全部楼层
在changePayment(str) get user select 的 traineeid
- xmlhttp.open("GET","changePay.php?loc="+str,true);
复制代码
在上面这个pass过去"changePay.php?loc="+str+"&traineeid ="+traineeid |
|
|
|
|
|
|
|
|
|
|
发表于 4-5-2012 11:16 PM
|
显示全部楼层
|
我这个是比较简单的。还有,如果要回复别人的贴,在那个人的贴下面按回复,别人才能知道你在回复他 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-5-2012 12:43 AM
|
显示全部楼层
回复 7# leon_lcl
哦。。好的。谢谢。我去试试。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-5-2012 10:39 PM
|
显示全部楼层
回复 7# leon_lcl
- function changePayment(str)
- {
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("paymentMethod").innerHTML=xmlhttp.responseText;
- }
- xmlhttp.open("GET","changePay.php?PaymentType="+str+"&TraineeID ="+TraineeID,true);
- }
- xmlhttp.send();
- }
复制代码
- <?php
- $PaymentType=$_GET["PaymentType"];
- $TraineeID_GET["TraineeID"];
- $con = mysql_connect('localhost', 'root', '');
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("pratice", $con);
- $sql="SELECT Fees FROM course,registration WHERE course.CourseName=registration.CourseName And registration.TraineeID = '".$TraineeID."'";
- $result = mysql_query($sql);
- echo "Amount:SGD$";
- while($row=mysql_fetch_array($result)){
- if ($PaymentType=='Installment')
- {
- $Amount=$row['Fees']/4;
- echo "$Amount";
- }
- else if ($PaymentType=='FullPayment')
- {
- $Amount=$row['Fees'];
- echo "$Amount";
- }
- }
- mysql_close($con);
- ?>
复制代码
还是做不到,是不是哪里出问题了? |
|
|
|
|
|
|
|
|
|
|
发表于 5-5-2012 10:52 PM
|
显示全部楼层
回复 10# h@@
你的TraineeID在function changePayment(str)都没有拿到value,怎样做到?拿value不是酱直接打他的id拿的 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-5-2012 11:09 PM
|
显示全部楼层
回复 11# leon_lcl
- function changePayment(str,TraineeID)
- {
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("paymentMethod").innerHTML=xmlhttp.responseText;
- }
- xmlhttp.open("GET","changePay.php?PaymentType="+str+"&TraineeID ="+TraineeID,true);
- }
- xmlhttp.send();
- }
复制代码
是这样吗?不好意思啊,我都是网上学的。有些东西不是很了解。 |
|
|
|
|
|
|
|
|
|
|
发表于 5-5-2012 11:23 PM
|
显示全部楼层
回复 12# h@@
试看看 document.getElementById("TraineeID").value
不过从你的- $res = mysql_query("SELECT TraineeID FROM registration ORDER BY TraineeID")
- or die("Invalid query: " . mysql_query());
- echo '<option value=""></option>';
- while ($row = mysql_fetch_assoc($res)) {
- $TraineeID = $row['TraineeID'];
- echo "<option value='$TraineeID'>$TraineeID</option>";
复制代码
你要validate user 有选到TraineeID |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|