Help with mysql php error proofing

i have my table with this columns scan_type, scan_location, and scan_wo_order so i have a scan system that insert data into my table but i see to much duplicated data so i make the error proofing to avoid that work then i see how many scan out but not scan in so i try to make a error proofing to avoid scan out without scanning IN however i can’t make that work

I TRY this but does not work
"

<?php
require "beta.con.php";

$conn = Connect();

$Scan_Type = $conn->real_escape_string($_POST["Scan_Type"]);

$Scan_Location = $conn->real_escape_string($_POST["Enter_Location"]);

$Scan_EmployeeID = $conn->real_escape_string($_POST["Enter_Employee_ID#"]);

$Scan_wo_number = $conn->real_escape_string($_POST["Scan_WO"]);

$Scan_step_number  = $conn->real_escape_string($_POST["Scan_step"]);

$sql1 = "select * from wss_scans where scan_location = '".$Scan_Location."' and scan_type = '".$Scan_Type."' and scan_wo_number = '".$Scan_wo_number."'"; \\this avoid duplicate scans this one works

$sql1query = mysqli_query($conn, $sql1);

$sql2 = "select * from wss_scans where scan_location = '".$Scan_Location."' and scan_type = '".$IN."' and scan_wo_number = '".$Scan_wo_number."'";

$sql2query = mysqli_query($conn, $sql2);

$row = mysqli_num_rows($sql2query);

if(mysqli_num_rows($sql2query) < 0){
  echo " Scan Work Order Number: $Scan_wo_number  IN First PLEASE Check Your Submition";
}
elseif(mysqli_num_rows($sql1query) > 0){
echo " Error Work Order Already Scan $Scan_Type  OR Scan Work Order Number: $Scan_wo_number  IN First PLEASE Check Your Submition";
}else{
$query = "Insert Into wss_scans (scan_type, scan_location, EmployeeID, scan_wo_number, scan_step_number)
							values ('" .$Scan_Type . "', '" . $Scan_Location. "', '" . $Scan_EmployeeID. "','" . $Scan_wo_number . "', '" .$Scan_step_number. "')";

$success = $conn->query($query);

if (!$success) {
 die("could not entry data contact Jose or Toby: " .$conn->error);
}
else
{
  echo "Data entry Successfully <br>";


}

}
$conn->close();

?>
"

the one that avoid duplicate insert work but not the one that require scan IN before scan OUT anyone have any idea how I can make that one work

In some mysqli installations there is potentially a problem if you execute a query but do not use the results of that query - it can cause issues with executing the next query. You could look at adding mysqli_free_result() after the first query.

In any case, as all you need is the number of rows for each query, perhaps you could look at using COUNT instead of actually retrieving the data?

ETA - is this a typo?

if(mysqli_num_rows($sql2query) < 0){

I can’t imagine a situation where you could possibly retrieve fewer than zero results from a query.

1 Like

thanks for the reply any idea how to achieve the require scan “IN” before scan “out” on scan type I try to use this

$sql2 = "select * from wss_scans where scan_location = '".$Scan_Location."' and scan_type = '".$IN."' and scan_wo_number = '".$Scan_wo_number."'";


if(mysqli_num_rows($sql2query) < 0){
  echo " Scan Work Order Number: $Scan_wo_number  IN First PLEASE Check Your Submission";
 or paste code here

that work not let any to insert scan type “OUT” before “IN” but also not let scan “IN” because always return “<0” so not let scan “IN” and “OUT”

I don’t use mysqli, I hadn’t realised there was a way that it would return a negative number of rows from a query, so I can’t really help on that.

What is the value of the $IN variable that you use in the second query?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.