php练习


<meta charset="UTF-8">
<html>
<style type="text/css" >
    .box{
        border: 1px dashed #0099cc;
        background-color: cornsilk;
        height: 100px;
        width: 280px;
        margin: auto;
    }
</style>
<body>
<form action="" method="post">
    <table border="1" align="center" cellpadding="0" cellspacing="0">
        <tr><td colspan="2" align="center" bgcolor="#999999">用户登录表单</td> </tr>
        <tr><td>用户名:</td><td><input name="username" type="text"></td></tr>
        <tr><td>密码:</td><td><input name="password" type="password" size="21"></td></tr>
        <tr><td colspan="2" align="center">
                <input type="submit" name="submit" value="登录">
                <input type="reset" name="submit2" value="重置">
            </td> </tr>
    </table>
    <h2 align="center"><font color="red">输入方程系数查看答案是多少吧!</font></h2>
    <div class="box">
        <input type="text" name="a" size="1">X²+
        <input type="text" name="b" size="1">X+
        <input type="text" name="c" size="1">=0
        <input type="submit" name="submit3" value="提交"></tr>
    </div>
    <div align="center"><td><input type="text" name="log" placeholder="写点什么吧!"></td>
        <input type="submit" name="submit4" value="提交"></div>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    if ($username == "admin" && $password == "123456") {
        echo "<script>alert('登录成功');</script>";
    }
    else {
        echo "<script>alert('登录失败');</script>";
    }
}
if(isset($_POST['submit3']))
{
    $a=$_POST['a'];
    $b=$_POST['b'];
    $c=$_POST['c'];
    $d=sqrt($b*$b-4*$a*$c);
    $result1=(-($b)+$d)/(2*$a);
    $result2=(-($b)-$d)/(2*$a);
    if($d<0)
    {
        echo "<script>";
        echo "alert('您输入的系数没有根!');";
        echo "</script>";
    }
    if($d==0){
        echo "<script>";
        echo "alert('您输入系数的跟是".$result1."');";
        echo "</script>";
    }
    if($d>0){
        echo "<script>";
        echo "alert('您输入系数的跟是".$result1."和".$result2."');";
        echo "</script>";
    }
}
if(isset($_POST['submit4'])){
    $log=$_POST['log'];
    echo "<table width=80 border=1 align=center bgcolor='#ff1493'>";
    echo "<tr><td>$log</td></tr>";
    echo "</table>";
}
?>

在这里插入图片描述

<meta charset="UTF-8">
<html>
<body>
<style>
    body{
        background-color: yellow;
    }
</style>
<form action="" method="post">
<div><font size="4" color="blue" face="黑体">计算累加和</font> </div>
<br action="" method="post">
    1+2+...+<input type="text" name="num" size="5">
    <input type="submit" name="submit" value="计算"><br/>
    <font size="4" color="green" face="幼圆">计算阶乘</font></br>
    请输入一个整数:<input type="text" name="num1" size="5">
    <input type="submit" name="submit1" value="计算">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
    $num=$_POST['num'];
    $i=0;
    $sum=0;
    if($num<=2)
        echo "<script>alert('输入的数字必须大于2');</script>";
    else {
        while ($i <= $num) {
            $sum = $sum + $i;
            $i++;
        }
        echo "<script>alert('1+2+...+$num=$sum');</script>";
    }
}
if(isset($_POST['submit1'])){
    $num1=$_POST['num1'];
    $j=$num1;
    $result=0;

    if($num1<=0)
        echo "<script>alert('请输入一个大于0的整数!');";
    else{
        for($j=$num1-1;$j>1;$j--){
            $num1=$num1*$j;
        }
        echo "<script>alert('您输入整数的阶乘是:$num1');</script>";
    }
}
?>

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

php调用函数

<meta charset="UTF-8">
<?php
function my_sort($array)
{
    for($i=0;$i<count($array);$i++)
    {
        for($j=$i+1;$j<count($array);$j++)
        {
            if($array[$i]>$array[$j])
            {
                $tmp=$array[$j];
                $array[$j]=$array[$i];
                $array[$i]=$tmp;
            }
        }
    }
    return $array;
}
function check($array1)
{
    for($x=0;$x<count($array1);$x++)
    {
        if($array1[$x]>10||$array1[$x]<0)
           return $array1[$x];
    }
}

function com($array2)
{
  if($array2[0]<$array2[1])
      return $array2[1];
  else
      return $array2[0];
}
echo "请输入需要排序的数据:<br/>";
echo "<form method=post>";
for($i=1;$i<6;$i++)
{
    echo "<input type='text' name='stu[]' size='5'>";
    if($i<5)
        echo "-";
}
echo "<input type='submit' name='bt' value='提交'></br>";
echo "请输入5个小于10的自然数:<br/>";
for($i=1;$i<6;$i++)
{
    echo "<input type='text' name='stu1[]' size='5'>";
}
echo "<input type='submit' name='submit' value='提交'></br>";
echo "请输入要进行比较的两个数:</br>";
for($i=1;$i<3;$i++)
{
    echo "<input type='text' name='stu2[]' size='5'>";
}
echo "<input type='submit' name='sub' value='提交'>";
echo "</form>";
if(isset($_POST['bt']))
{
    $stu=$_POST['stu'];
    $arr_stu=my_sort($stu);
    echo "排序的数据如下所示:<br/>";
    while(list($key,$value)=each($arr_stu))
    {
        echo $value."&nbsp;";
    }
}
if(isset($_POST['submit']))
{
    $stu1=$_POST['stu1'];
    $a1=check($stu1);
    if($a1>10)
        echo "存在不符合要求的数!";
    else
        echo "输入的数据正确!";
}
if(isset($_POST['sub']))
{
    $stu2=$_POST['stu2'];
    $b1=com($stu2);
    echo "较大的数是:".$b1;
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值