douzun4443 2016-08-07 23:15
浏览 61
已采纳

如果value = Button?

I want to send a form if someone has enough money, but if someone doesn't have enough money, the form should be disabled.

I though it would be something like this:

<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();

if(!$user_home->is_logged_in())
{
        $user_home->redirect('index.php');
}

$stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

?>

<?php


                require_once 'mailer/class.phpmailer.php';

                $mail = new PHPMailer(true);

                if(isset($_POST['kaufen']))
                {
                        $name  = strip_tags($_POST['name']);
                        $email      = strip_tags($_POST['email']);
                        $total      = strip_tags($_POST['total']);
                        $menge      = strip_tags($_POST['menge']);
                        $item      = strip_tags($_POST['item']);
                        $subject    = "Bestellung / Kevin-Bank.ch";
                        $text_message    = "Du hast erfolgreich etwas in unsere Shop bestellt. <br /><br /> Item: ".$item." <br > Menge:".$menge." <br > Totalkosten: ".$total."dM <br /><br /> Wir liefern dein Item so schnell wie wir es können";




                        $message  = "<html><body>";

                        $message .= "<table width='100%' bgcolor='#e0e0e0' cellpadding='0' cellspacing='0' border='0'>";

                        $message .= "<tr><td>";

                        $message .= "<table align='center' width='100%' border='0' cellpadding='0' cellspacing='0' style='max-width:650px; background-color:#fff; font-family:Verdana, Geneva, sans-serif;'>";

                        $message .= "<thead>
                                                <tr height='80'>
                                                        <th colspan='4' style='background-color:#f5f5f5; border-bottom:solid 1px #bdbdbd; font-family:Verdana, Geneva, sans-serif; color:#333; font-size:34px;' >Kevin-Bank.ch</th>
                                                </tr>
                                                </thead>";

                        $message .= "<tbody>
                                                <tr align='center' height='50' style='font-family:Verdana, Geneva, sans-serif;'>
                                                        <td style='background-color:#00a2d1; text-align:center;'><a href='http://www.kevin-bank.ch/index.php' style='color:#fff; text-decoration:none;'>Anmelden</a></td>
                                                        <td style='background-color:#00a2d1; text-align:center;'><a href='http://www.kevin-bank.ch/shop.php' style='color:#fff; text-decoration:none;' >Shop</a></td>
                                                        <td style='background-color:#00a2d1; text-align:center;'><a href='http://www.kevin-bank.ch/bank.php' style='color:#fff; text-decoration:none;' >Bank</a></td>
                                                        <td style='background-color:#00a2d1; text-align:center;'><a href='http://www.kevin-bank.ch/slot-machine.php' style='color:#fff; text-decoration:none;' >Casino</a></td>
                                                </tr>

                                                <tr>
                                                        <td colspan='4' style='padding:15px;'>
                                                                <p style='font-size:20px;'>Hi' ".$name.",</p>
                                                                <hr />
                                                                <p style='font-size:25px;'>Danke fürs bestellen in unsere Website.</p>
                                                                <img src='https://www.minecraft-italia.it/images/crafting-2.0/150/275.png' alt='' style='height:auto; width:100%; max-width:100%;' />
                                                                <p style='font-size:15px; font-family:Verdana, Geneva, sans-serif;'>".$text_message.".</p>
                                                        </td>
                                                </tr>

                                                <tr height='80'>
                                                        <td colspan='4' align='center' style='background-color:#f5f5f5; border-top:dashed #00a2d1 2px; font-size:24px; '>
                                                        <label>
                                                        Kevin-Bank.ch - Team
                                                        </td>
                                                </tr>

                                                </tbody>";

                        $message .= "</table>";

                        $message .= "</td></tr>";
                        $message .= "</table>";

                        $message .= "</body></html>";


                        try
                        {
                                $mail->IsSMTP();
                                $mail->isHTML(true);
                                $mail->SMTPDebug  = 0;
                                $mail->SMTPAuth   = true;
                                $mail->SMTPSecure = "smtp";
                                $mail->Host       = "ke****.ch";
                                $mail->Port       = 25;
                                $mail->AddAddress($email);
                                $mail->Username   ="suppo*****-bank.ch";
                                $mail->Password   ="****!";
                                $mail->SetFrom('s****bank.ch','Kevin-Bank.ch');
                                $mail->AddReplyTo("****bank.ch","Kevin-Bank.ch");
                                $mail->Subject    = $subject;
                                $mail->Body           = $message;
                                $mail->AltBody    = $message;

                                if($mail->Send())
                                {

                                        $msg = "<div class='alert alert-success'>
                                                        Bestellung wurde gesendet, du kriegst gleich ein Best&auml;tigungsmail.
                                                        </div>";

                                }
                        }
                        catch(phpmailerException $ex)
                        {
                                $msg = "<div class='alert alert-warning'>".$ex->errorMessage()."</div>";
                        }
                }

?>


<?php include_once 'header.php'; ?>

        <div id="wrapper">

        <div class="container">

            <div class="page-header">
            <h3>Kevin-Bank.ch - Bank & Shop und bald vieles mehr!</h3>
            </div>
        <h5>Folgende Item bestellst du gerade : Eisebeinschutz</h5>
           <div class="email-form">

            <?php
                if(isset($msg))
                {
                        echo $msg;
                }
                ?>
        <form action="" method="post">
        <input type=text class=hidden name=item value="Eisebeinschutz">
        <input type=text class=hidden name=name value="<?php echo $row['userName']; ?>" required/>
        <input type=text class=hidden name=email value="<?php echo $row['userEmail']; ?>" required/> 
        <hr >

        <label>Preis pro Stack:</label>
        <input disabled type=text class="form-control" name=kosten id="kosten" required="required" value="56 dM"/>
        <p></p>
        <label>Menge:</label>
          <select class="form-control" id="menge" name="menge" onblur="calculate()"/>
          <option readonly>Bitte auswählen</option>
          <option value="1 Stück">1 Stück</option>
          <option value="2 Stück">2 Stück</option>
          <option value="3 Stück">3 Stück</option>
          <option value="4 Stück">4 Stück</option>
          <option value="5 Stück">5 Stück</option>
          <option value="6 Stück">6 Stück</option>
          <option value="7 Stück">7 Stück</option>
          <option value="8 Stück">8 Stück</option>
          <option value="9 Stück">9 Stück</option>
          <option value="10 Stück">10 Stück</option>


          </select> 
        <p></p>
        <label>Totalkosten: (Wenn die Totalkosten nicht funktoniert, klickt einfach irgendwo und es sollte dann sich aktualisieren.)</label>
        <input readonly type=text class=form-control name="total" id="total" required="required" /><br >
        <?php
    $balance = 3;
    if($balance 0) { ?>
    <button disabled type="sumbit" name='einzahlen' class="btn btn-info btn-block btn-md">Pin einlösen</button> <?
    }

    if($balance > 2){ ?>
    <button type="sumbit" name='einzahlen' class="btn btn-info btn-block btn-md">Pin einlösen</button> <?
    }
?>
        </form>
        <hr >

        <img src="https://www.minecraft-italia.it/images/crafting-2.0/150/275.png" class="img-circle center-block" alt="">

            </div>

        <?php
if(isset($_POST["kaufen"])){
$hostname='localhost:3306';
$username='*****';
$password='******!';

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=****",$username,$password);

    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line


$sql = "INSERT INTO bestellung (name, email, item, menge, total)
VALUES ('".$_POST["name"]."','".$_POST["email"]."','".$_POST["item"]."','".$_POST["menge"]."','".$_POST["total"]."')";


if ($dbh->query($sql)) {

}
else{
     echo "<script type= 'text/javascript'>alert('Etwas stimmt mit Mysql nicht, bitte melde dich bei Kevin4K!');</script>";
}

    $dbh = null;
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }

}
?>

    <script src="asets/jquery-1.11.3-jquery.min.js"></script>
    <script src="asets/js/bootstrap.min.js"></script>

<script>
calculate = function()
{
    var resources = document.getElementById('kosten').value;
    var minutes = document.getElementById('menge').value; 
    document.getElementById('total').value = parseInt(resources)*parseInt(minutes);

   }
</script>


</body>
</html>

But this doesn't work.

Can anyone help me?

  • 写回答

1条回答 默认 最新

  • dsilhx5830 2016-08-07 23:20
    关注

    I can't test my code right now, but I think something like this should work:

    <?php
        $balance = 3;
        if($balance <= 0) { ?>
            <button disabled type="sumbit" name='einzahlen' class="btn btn-info btn-block btn-md">Pin einlösen</button> <?
        }
    
        if($balance > 2){ ?>
            <button type="sumbit" name='einzahlen' class="btn btn-info btn-block btn-md">Pin einlösen</button> <?
        }
    ?>
    

    There are a few changes I made. The main reason you can't properly run your code is because you tried to compare a string with an integer. The other reason is because you didn't close php when you started writing html code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障