PHP检查多文本文本框并插入数据错误[重复]

时间:2022-09-22 17:08:19

This question already has an answer here:

这个问题在这里已有答案:

<?php
              $carCompany = $mysqli->real_escape_string($_POST['carCompanyName']);
              $carName = $mysqli->real_escape_string($_POST['carName']);
              $carModel = $mysqli->real_escape_string($_POST['carModel']);
              $carColor = $mysqli->real_escape_string($_POST['carColor']);
              $carFuelType = $mysqli->real_escape_string($_POST['carFuelType']);
              $carPlate = $mysqli->real_escape_string($_POST['carPlate']);
              $carOwnerName = $mysqli->real_escape_string($_POST['carOwnerName']);
              $carDescription = $mysqli->real_escape_string($_POST['carDescription']);

              if ($_POST) {
                if (!isset($_POST['carCompanyName'])) || strlen($_POST['carCompanyName'])<1 {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carName'])) || strlen($_POST['carName'])<1 {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carModel'])) || strlen($_POST['carModel'])<1 {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carColor'])) || strlen($_POST['carColor'])<1 {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carPlate'])) || strlen($_POST['carPlate'])<1 {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carOwnerName'])) || strlen($_POST['carOwnerName'])<1 {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carOwnerName'])) || strlen($_POST['carOwnerName'])<1 {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }

                if(mysqli_query($mysqli, "INSERT INTO cars(car_plate_no, car_company_name, car_name, car_model, car_color, car_fuel_type, car_owner_name, car_description) VALUES ('$carPlate','$carCompany','$carName','$carModel','$carColor','$carFuelType','$carOwnerName','$carDescription')" )){
                    printf("%d Row Inserted.\n", mysqli_affected_rows($mysqli));
                  }

              }

              ?>

Error Says : Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in C:\xampp\htdocs\meccaniko\work\profile\add-car.php on line 33

错误说:解析错误:语法错误,意外'||'第33行的C:\ xampp \ htdocs \ meccaniko \ work \ profile \ add-car.php中的(T_BOOLEAN_OR)

what happened with this code it says || this is unexpected

这个代码发生了什么,它说||这是出乎意料的

help me to check empty textboxes and run the above insert query

帮我检查空文本框并运行上面的插入查询

2 个解决方案

#1


1  

You have the ) on the wrong positions.

你有错误的位置。

if (!isset($_POST['carCompanyName']) || strlen($_POST['carCompanyName'])<1) {

}

#2


0  

Replace this code with above, I have corrected code mistake of brackets on all if conditions.

用上面的代码替换这个代码,我已经纠正了所有情况下代码的代码错误。

<?php
              $carCompany = $mysqli->real_escape_string($_POST['carCompanyName']);
              $carName = $mysqli->real_escape_string($_POST['carName']);
              $carModel = $mysqli->real_escape_string($_POST['carModel']);
              $carColor = $mysqli->real_escape_string($_POST['carColor']);
              $carFuelType = $mysqli->real_escape_string($_POST['carFuelType']);
              $carPlate = $mysqli->real_escape_string($_POST['carPlate']);
              $carOwnerName = $mysqli->real_escape_string($_POST['carOwnerName']);
              $carDescription = $mysqli->real_escape_string($_POST['carDescription']);

              if ($_POST) {
                if (!isset($_POST['carCompanyName']) || strlen($_POST['carCompanyName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carName']) || strlen($_POST['carName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carModel']) || strlen($_POST['carModel'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carColor']) || strlen($_POST['carColor'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carPlate']) || strlen($_POST['carPlate'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carOwnerName']) || strlen($_POST['carOwnerName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carOwnerName']) || strlen($_POST['carOwnerName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }

                if(mysqli_query($mysqli, "INSERT INTO cars(car_plate_no, car_company_name, car_name, car_model, car_color, car_fuel_type, car_owner_name, car_description) VALUES ('$carPlate','$carCompany','$carName','$carModel','$carColor','$carFuelType','$carOwnerName','$carDescription')" )){
                    printf("%d Row Inserted.\n", mysqli_affected_rows($mysqli));
                  }

              }

              ?>

#1


1  

You have the ) on the wrong positions.

你有错误的位置。

if (!isset($_POST['carCompanyName']) || strlen($_POST['carCompanyName'])<1) {

}

#2


0  

Replace this code with above, I have corrected code mistake of brackets on all if conditions.

用上面的代码替换这个代码,我已经纠正了所有情况下代码的代码错误。

<?php
              $carCompany = $mysqli->real_escape_string($_POST['carCompanyName']);
              $carName = $mysqli->real_escape_string($_POST['carName']);
              $carModel = $mysqli->real_escape_string($_POST['carModel']);
              $carColor = $mysqli->real_escape_string($_POST['carColor']);
              $carFuelType = $mysqli->real_escape_string($_POST['carFuelType']);
              $carPlate = $mysqli->real_escape_string($_POST['carPlate']);
              $carOwnerName = $mysqli->real_escape_string($_POST['carOwnerName']);
              $carDescription = $mysqli->real_escape_string($_POST['carDescription']);

              if ($_POST) {
                if (!isset($_POST['carCompanyName']) || strlen($_POST['carCompanyName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carName']) || strlen($_POST['carName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carModel']) || strlen($_POST['carModel'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carColor']) || strlen($_POST['carColor'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carPlate']) || strlen($_POST['carPlate'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carOwnerName']) || strlen($_POST['carOwnerName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }
                if (!isset($_POST['carOwnerName']) || strlen($_POST['carOwnerName'])<1) {

                  die('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Danger!</strong> Indicates a dangerous or potentially negative action.</div>');
                }

                if(mysqli_query($mysqli, "INSERT INTO cars(car_plate_no, car_company_name, car_name, car_model, car_color, car_fuel_type, car_owner_name, car_description) VALUES ('$carPlate','$carCompany','$carName','$carModel','$carColor','$carFuelType','$carOwnerName','$carDescription')" )){
                    printf("%d Row Inserted.\n", mysqli_affected_rows($mysqli));
                  }

              }

              ?>