21-08-2008, 12:33 AM
|
#1 (permalink)
|
| عضو جديد
تاريخ الانتساب: 21-08-2008 المكان: الخليل/فلسطين السن: 36
مشاركات: 17
مستوى السمعة : 0 | مشكلة في كود جمع وطرح وضرب وقسمة في لغة php بسم الله الرحمن الرحيم
إخواني في الله
السلام عليكم ورحمة الله وبركاته
لدي مشكلة في لغة php المشكلة هي أن عندي كود جمع وطرح وضرب وقسمة هذا هو الكود
الملف الأول كما يلي واسمه calc22.html كود PHP: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
****** http-*****="*******-Type" *******="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="calc22.php">
number1 :
<label>
<input type="text" name="n1" />
</label>
<p>number2 :
<label>
<input type="text" name="n2" />
</label>
</p>
<p>please enter your choice between 1 and 4 </p>
<p>1=add</p>
<p>2=sub</p>
<p>3=div</p>
<p>4=mul</p>
<p>
<label>
<input type="text" name="choice" />
</label>
</p>
<input type="submit" value ="send" >
<p> </p>
</form>
<br /><div style="z-index:3" class="smallfont" align="center">Search Engine Optimization by vBSEO 3.2.0</div></body>
</html>
أما الملف الثاني واسمه calc22.php كود PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
****** http-*****="*******-Type" *******="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
function add($n1,$n2)
{
$sum=$n1+$n2;
echo $sum;
}
echo "this is my add function<br>";
add ($_POST["n1"],$_POST["n2"]);
function sub($n1,$n2)
{
$subtract=$n1-$n2;
echo $subtract;
}
echo "this is my subtract function<br>";
sub ($_POST["n1"],$_POST["n2"]);
function div($n1,$n2)
{
$division=$n1/$n2;
echo $division;
}
echo "this is my division function<br>";
div ($_POST["n1"],$_POST["n2"]);
function mul($n1,$n2)
{
$multiply=$n1+$n2;
echo $multiply;
}
echo "this is my multiply function<br>";
mul ($_POST["n1"],$_POST["n2"]);
?>
</body>
</html> نتيجة هذين الملفين هي جمع وطرح وضرب وقسمة عددين والكود ما فيه أي مشكلة
أريد أن أقوم بتعديل في الكود بحيث أنني لا أقوم بعملية الجمع إلا بعد الضغط على رقم 1 والطرح بعد الضغط على رقم 2 وعملية القسمة لا تتم إلا بعد الضغط على رقم 3 وعملية الضرب لا تتم إلا بعد الضغط على رقم 4 وهذا هو الكود للملف الأول واسمه calc222.html كود PHP: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
****** http-*****="*******-Type" *******="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="calc222.php">
number1 :
<label>
<input type="text" name="n1" />
</label>
<p>number2 :
<label>
<input type="text" name="n2" />
</label>
</p>
<p>please enter your choice between 1 and 4 </p>
<p>1=add</p>
<p>2=sub</p>
<p>3=div</p>
<p>4=mul</p>
<p>
<label>
<input type="text" name="choice" />
</label>
</p>
<input type="submit" value ="send" >
<p> </p>
</form>
</body>
</html>
أما الكود للملف الثاني واسمه calc222.php فهذا هو كود PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
****** http-*****="*******-Type" *******="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
function add($n1,$n2)
{
$sum=$n1+$n2;
echo $sum;
}
echo "this is my add function<br>";
add ($_POST["n1"],$_POST["n2"]);
function sub($n1,$n2)
{
$subtract=$n1-$n2;
echo $subtract;
}
echo "this is my subtract function<br>";
sub ($_POST["n1"],$_POST["n2"]);
function div($n1,$n2)
{
$division=$n1/$n2;
echo $division;
}
echo "this is my division function<br>";
div ($_POST["n1"],$_POST["n2"]);
function mul($n1,$n2)
{
$multiply=$n1*$n2;
echo $multiply;
}
echo "this is my multiply function<br>";
mul ($_POST["n1"],$_POST["n2"]);
?>
</body>
</html> فأين المشكلة في الكود في الملف calc222.html والملف calc222.php
أرجو أن تكون المشكلة واضحة
أخوكم المحب لكم في الله / لؤي (أبو العبد) |
| |