1

そのため、(パスワード/電子メールが正しくない)、(すべてのフィールドに入力) などのエラー警告を同じスタイルで異なるテキストでエコーしようとしていますが、スタイル全体をエコーせずにこれを行うためのショートカットを見つけることができないようです。すべてのエコー、これはほとんどの人にとって痛々しいほど明らかだと確信しているので、助けてください。TVM .コードは次のとおりです。

   if ($oldpassword!==$oldpassworddb)
     { echo"<head>

<style type='text/css'>
.tab2

{
   width:400px; height:40px;
   position: absolute; right: 300px; top: 70px;
}
 .td2
{
    background-color:pink;
    color:blue;
    text-align:center;
}

</style>
</head>
<body>
<table class='tab2'>
<td class='td2'>first meggage</td>
</table>
</body>";}

else if (strlen($newpassword)>25||strlen($newpassword)<6)
   {echo "what should I put in here!!! ">second message;}
4

1 に答える 1

0

あなたはこれに間違って近づいています。PHP ロジックと出力 HTML を混在させないでください。

何かを出力する前に最初に表示するメッセージを決定し、それを変数に格納します。次に、変数を配置してすべての HTML を出力します。これにより、事前に必要な他の変数を定義し、それらすべてを出力に同時に挿入することができます。

<?php
// First define the $message variable
$message = "";
if ($oldpassword!==$oldpassworddb) {
  $message = "first message";
}
else if (strlen($newpassword)>25||strlen($newpassword)<6) {
  $message = "Second message";
}
else {
  // some other message or whatever...
}
Close the <?php tag so you can output HTML directly
?>

次に、HTML を出力します (DOCTYPE を忘れないでください!)。

<!DOCTYPE html>
<head>

<style type='text/css'>
.tab2

{
   width:400px; height:40px;
   position: absolute; right: 300px; top: 70px;
}
 .td2
{
    background-color:pink;
    color:blue;
    text-align:center;
}

</style>
</head>
<body>
<table class='tab2'>
<!-- the PHP variable is inserted here, using htmlspecialchars() in case it contains <>&, etc -->
<td class='td2'><?php echo htmlspecialchars($message); ?></td>
</table>
</body>

レイアウトに使用することは、現代の良い方法とは見なされません。CSS を のタグを<table>介してリンクされた外部の .css ファイルに移動することをお勧めしますが、最初に PHP の問題に対処する必要があります。<link rel='stylesheet' src='yourcss.css'><head>

于 2012-07-18T17:46:20.873 に答える