こんにちは、サーバー側とクライアント側の両方で 3 つのことを検証する方法を知りたいと思っていました。
データベース テーブル製品
私のデータベースはこのように見えますが、400 以上のデータがあります。
pid name size
1 grey 12 inch
2 blue 16 inch
database table category
pid category
1 vans
2 nike
database table itemised
pid price
1 30.00
2 50.00
確認する必要があるフィールドがいくつかあります。空でないことを確認するために、すでに検証を行っています。
私のテーブルのフィールドの1つは次のようになります
<select id="Category" name="Category">
<?php
dbconnect();
$stmt = $conn->prepare("SELECT Name FROM Category WHERE pid=:id");
$stmt->bindParam('id',$id);
$stmt->execute();
$i = 0;
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
if ($i == 0) {
echo '<option SELECTED value="'.$row['Name'].'">'.$row['Name'].'</option>
';
}
else {
echo '<option value="'.$row['Name'].'">'.$row['Name'].'</option>';
}
$i++;
}
?>
</select>
形式ではなく表です。size
as番号に気づいたら、それを入力してください。
私の質問 多かれ少なかれ、投稿された値を変更するための開発者ツールに精通しているすべての人。client(JS) と client(php) の両方を検証して、誰も値を台無しにしないようにします。
例として
空でないことを確認するためにこれを行いましたnormal
<option value="blue vans">blue vans</option>
not-normal
<option value="">blue vans</option> // in this one the value is `BLANKET`
以下のjsはこれをチェックします
function isEmpty(aTextField,errormessage) //null may be used for errormessage to only change the colour of matching fields
{
if (aTextField.value.length<=0)
{
if (lfield != aTextField || lfield === null) { fields[fields.length] = [aTextField,false]; } else { fields[fields.length-1] = [aTextField,false]; }
lfield = aTextField;
if (errormessage !== "")
{
if (counter < error_count || error_count == 0) { errors += errormessage+'\n'; } counter++;
}
return true;
}
else
{
if (lfield != aTextField || lfield === null) { fields[fields.length] = [aTextField,true]; }
lfield = aTextField;
return true;
}
}
PHPで
function notEmpty($inputname,$error_message)
{
$this->js.='if (!isEmpty(formname.'.$inputname.',"'.$error_message.'")) return false;';
if ( isset($_POST[$inputname]) && ( strlen($_POST[$inputname]) <= 0 ))
{
if ($error_message != null)
{
$this -> error_message .= $error_message.'<br>';
}
}
}
これで、テーブル内のすべてのオプションのブランケット値を検証する方法がわかります。js と php の両方で検証するにはどうすればよいですか
最後に持っていなかったsize
場合はちょっと簡単ですinch
が、データベース内の1000を超えるデータを変更するのは面倒です。
どうすればこれを行うことができますか?
これを明確に説明したことを願っています。そうでない場合は、コメントを残してください。質問を言い換えてみます.
ありがとう