|
|
|
ช่วยดูหน่อยครับ ปัญหาcode php ผลลัพธ์มันแสดงทั้ง error แล้วก็ตาราง |
|
|
|
|
|
|
|
คือผมตั้งconditionให้มัน แต่พอผมใส่ค่า error ตัวนึง มันกลับแสดงตารางผลลัพธ์ด้วยทั้้งๆ ที่ผมอยากให้มันโชว์แค่ ข้อความอย่างเดียว
Code (PHP)
<?php
if ( isset($_POST['submit'])){
extract ($_REQUEST);
if ($credit1 < 1 || $credit1 > 5){
print "Error! Your unit is overload";
}
$sc = array ('!', '@', '#',' $', '%', '^', '&', '*', '(', ')',' [', ']',' {',' }', '?',' /',' +',' =',' -');
foreach ($sc as $prohibit )
{
if ( substr($subject1,0) == $prohibit || substr($subject2,0) == $prohibit || substr($subject3,0) == $prohibit || substr($subject4,0) == $prohibit)
{
print "Ada masaalah";
}
}
print "<b><big>Transcript Report</b></big><br/>";
if($score1 > 84){
$eval1 = "A";
}
else if($score1 > 74){
$eval1 = "B";
}
else if($score1 > 59){
$eval1 = "C";
}
else if($score1 > 49){
$eval1 = "D";
}
else {
$eval1 = "E";
}
if($score2 > 84){
$eval2 = "A";
}
else if($score2 > 74){
$eval2 = "B";
}
else if($score2 > 59){
$eval2 = "C";
}
else if($score2 > 49){
$eval2 = "D";
}
else {
$eval2 = "E";
}
if($score3 > 84){
$eval3 = "A";
}
else if($score3 > 74){
$eval3 = "B";
}
else if($score3 > 59){
$eval3 = "C";
}
else if($score3 > 49){
$eval3 = "D";
}
else {
$eval3 = "E";
}
if($score4 > 84){
$eval4 = "A";
}
else if($score4 > 74){
$eval4 = "B";
}
else if($score4 > 59){
$eval4 = "C";
}
else if($score4 > 49){
$eval4 = "D";
}
else {
$eval4 = "E";
}
print "<table border=1>
<tr>
<th>COURSE</th> <th>UNIT</th> <th>GRADE</th> <th>EVALUATION</th>
</tr>
<tr>
<td>$subject1</td> <td>$credit1</td> <td>$score1</td> <td>$eval1</td>
</tr>
<tr>
<td>$subject2</td> <td>$credit2</td> <td>$score2</td> <td>$eval2</td>
</tr>
<tr>
<td>$subject3</td> <td>$credit3</td> <td>$score3</td> <td>$eval3</td>
</tr>
<tr>
<td>$subject4</td> <td>$credit4</td> <td>$score4</td> <td>$eval4</td>
</tr>
</table>";
$total = $credit1+$credit2+$credit3+$credit4;
$avg = ($score1+$score2+$score3+$score4)/4;
print "<br> Total units taken : $total <br><br>";
print "Average grade : $avg <br>";
}
else{ ?>
<html><head><title>Transcript Report Form</title></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<h1 align = center>TRANSCRIPT REPORT FORM</h1>
<table align = center>
<tr>
<th>Course Name</th> <th>Units(1-5)</th> <th>Grade(0-100)</th>
</tr>
<tr>
<td><input type="text" size=30 name="subject1" /></td>
<td><input type="text" name="credit1" maxlength="1"/>
</td> <td><input type="text" name="score1" maxlength="3"/></td>
</tr>
<tr>
<td><input type="text" size=30 name="subject2" /></td>
<td><input type="text" name="credit2" maxlength="1"/></td>
<td><input type="text" name="score2" maxlength="3"/></td>
</tr>
<tr>
<td><input type="text" size=30 name="subject3" /></td>
<td><input type="text" name="credit3" maxlength="1"/></td>
<td><input type="text" name="score3" maxlength="3"/></td>
</tr>
<tr>
<td><input type="text" size=30 name="subject4" /></td>
<td><input type="text" name="credit4" maxlength="1" /></td>
<td><input type="text" name="score4" maxlength="3" /></td>
</tr>
</table>
<p align = center> <input type="submit" name="submit" value="Submit" /></p>
</form>
</html>
<?php } ?>
Tag : PHP
|
|
|
|
|
|
Date :
2012-03-24 11:29:44 |
By :
ฮาลีม |
View :
931 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
extract ($_REQUEST);
//if($_POST['submit']=="Submit" and (strlen($subject1) >0 and strlen($credit1) >0))
//{
if ($_POST['submit']=="Submit" and (strlen($subject1) >0 and strlen($credit1) >0))
{
if ($credit1 < 1 || $credit1 > 5)
{
print "Error! Your unit is overload";
}
$sc = array ('!', '@', '#',' $', '%', '^', '&', '*', '(', ')',' [', ']',' {',' }', '?',' /',' +',' =',' -');
foreach ($sc as $prohibit )
{
if ( substr($subject1,0) == $prohibit || substr($subject2,0) == $prohibit || substr($subject3,0) == $prohibit || substr($subject4,0) == $prohibit)
{
print "Ada masaalah";
}
}
print "<b><big>Transcript Report</b></big><br/>";
if($score1 > 84){
$eval1 = "A";
}
else if($score1 > 74){
$eval1 = "B";
}
else if($score1 > 59){
$eval1 = "C";
}
else if($score1 > 49){
$eval1 = "D";
}
else {
$eval1 = "E";
}
if($score2 > 84){
$eval2 = "A";
}
else if($score2 > 74){
$eval2 = "B";
}
else if($score2 > 59){
$eval2 = "C";
}
else if($score2 > 49){
$eval2 = "D";
}
else {
$eval2 = "E";
}
if($score3 > 84){
$eval3 = "A";
}
else if($score3 > 74){
$eval3 = "B";
}
else if($score3 > 59){
$eval3 = "C";
}
else if($score3 > 49){
$eval3 = "D";
}
else {
$eval3 = "E";
}
if($score4 > 84){
$eval4 = "A";
}
else if($score4 > 74){
$eval4 = "B";
}
else if($score4 > 59){
$eval4 = "C";
}
else if($score4 > 49){
$eval4 = "D";
}
else {
$eval4 = "E";
}
print "<table border=1>
<tr>
<th>COURSE</th> <th>UNIT</th> <th>GRADE</th> <th>EVALUATION</th>
</tr>
<tr>
<td>$subject1</td> <td>$credit1</td> <td>$score1</td> <td>$eval1</td>
</tr>
<tr>
<td>$subject2</td> <td>$credit2</td> <td>$score2</td> <td>$eval2</td>
</tr>
<tr>
<td>$subject3</td> <td>$credit3</td> <td>$score3</td> <td>$eval3</td>
</tr>
<tr>
<td>$subject4</td> <td>$credit4</td> <td>$score4</td> <td>$eval4</td>
</tr>
</table>";
$total = $credit1+$credit2+$credit3+$credit4;
$avg = ($score1+$score2+$score3+$score4)/4;
print "<br> Total units taken : $total <br><br>";
print "Average grade : $avg <br>";
}
else
{ ?>
<html><head><title>Transcript Report Form</title></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<h1 align = center>TRANSCRIPT REPORT FORM</h1>
<table align = center>
<tr>
<th>Course Name</th> <th>Units(1-5)</th> <th>Grade(0-100)</th>
</tr>
<tr>
<td><input type="text" size=30 name="subject1" /></td>
<td><input type="text" name="credit1" maxlength="1"/>
</td> <td><input type="text" name="score1" maxlength="3"/></td>
</tr>
<tr>
<td><input type="text" size=30 name="subject2" /></td>
<td><input type="text" name="credit2" maxlength="1"/></td>
<td><input type="text" name="score2" maxlength="3"/></td>
</tr>
<tr>
<td><input type="text" size=30 name="subject3" /></td>
<td><input type="text" name="credit3" maxlength="1"/></td>
<td><input type="text" name="score3" maxlength="3"/></td>
</tr>
<tr>
<td><input type="text" size=30 name="subject4" /></td>
<td><input type="text" name="credit4" maxlength="1" /></td>
<td><input type="text" name="score4" maxlength="3" /></td>
</tr>
</table>
<p align = center> <input type="submit" name="submit" value="Submit" /></p>
</form>
</html>
<?php }
?>
|
ประวัติการแก้ไข 2012-03-24 14:06:40
|
|
|
|
Date :
2012-03-24 13:05:52 |
By :
mangkunzo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|