I am very new to PHP and I am having some issues with validating the data against what is already stored in another table. The idea is pretty simple in that someone will enter some data against a works order and write that to the database. The data will only be written to the database if the works order number exists in a separate table.
$sqlv = "Select count (worksorderv) from validationtest where worksorderv = ('".$_POST["worksorder"]."')";
$checkwo = sqlsrv_query($conn, $sqlv, array(), array('Scrollable' => 'buffered'));
if (sqlsrv_fetch_array($checkwo) < 1) {
echo "That is not a valid works order.<br />";
}else{
$sql = "INSERT INTO main_table (worksorder, part, quantity, date)
VALUES ('".$_POST["worksorder"]."','".$_POST["part"]."','".$_POST["quantity"]."',GETDATE())";
$res = sqlsrv_query($conn, $sql);
I have tried to create a count, so if the works order does not exist within the table it will output a 0 else it exists and can be committed to the database.
if I hardcode a single number in I can get it to work, but I can not get it working using the $_POST["worksorder"] which is the form entry.
it seems to ignore and writes all entries regardless of if the count is 0 or 1
Any help is greatly appreciated!