From ff71083b49429f652e0746822ad7af2e9e45deca Mon Sep 17 00:00:00 2001 From: Rod Wright Date: Wed, 18 Feb 2026 12:40:40 -0500 Subject: [PATCH] fixes to get_part_data to prevent php undefined variable warnings --- distfiles/functions.php | 45 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/distfiles/functions.php b/distfiles/functions.php index d737cc4..3944c6e 100644 --- a/distfiles/functions.php +++ b/distfiles/functions.php @@ -757,43 +757,45 @@ function get_part_data($partinputdata) { // partid, uid, partnum, sernum, partname, result // where result=0 for success, 1 for no data found, 2 for mismatch global $db; + $checkmm = FALSE; + $result = 0; // pull input data from input array - if ($partinputdata['partid'] && $partinputdata['partid'] != "") $partid= $partinputdata['partid']; - if ($partinputdata['uid'] && $partinputdata['uid'] != "") $uid= $partinputdata['uid']; - if ($partinputdata['partnum'] && $partinputdata['partnum'] != "") $partnum= $partinputdata['partnum']; - if ($partinputdata['sernum'] && $partinputdata['sernum'] != "") $sernum= $partinputdata['sernum']; + $partid = (array_key_exists('partid', $partinputdata) && $partinputdata['partid'] != "") ? $partinputdata['partid'] : NULL; + $uid = (array_key_exists('uid', $partinputdata) && $partinputdata['uid'] != "") ? $partinputdata['uid'] : NULL; + $partnum = (array_key_exists('partnum', $partinputdata) && $partinputdata['partnum'] != "") ? $partinputdata['partnum'] : NULL; + $sernum = (array_key_exists('sernum', $partinputdata) && $partinputdata['sernum'] != "") ? $partinputdata['sernum'] : NULL; // for part data supplied, see what info is available // if a partid is supplied, pull other info from parts if ($partid) { // if partid supplied - $partqry=mysqli_query($db,"select * from parts where partid=\"$partid\""); + $partqry = mysqli_query($db, "select * from parts where partid=\"$partid\""); } else if ($uid && (!$partnum && !$sernum)) { // if uid only supplied - $partqry=mysqli_query($db,"select * from parts where uid like \"$uid\""); + $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\""); } else if (($partnum && $sernum) && !$uid) { // if pn/sn only supplied - $partqry=mysqli_query($db,"select * from parts where partnum=\"$partnum\" and sernum=\"$sernum\""); - } else if ($uid && $partnum && $sernum ) { //if uid and pn/sn supplied - $partqry=mysqli_query($db,"select * from parts where uid like \"$uid\" and partnum=\"$partnum\" and sernum=\"$sernum\""); - $checkmm=1; - $mismatchqry=mysqli_query($db,"select * from parts where + $partqry = mysqli_query($db, "select * from parts where partnum=\"$partnum\" and sernum=\"$sernum\""); + } else if ($uid && $partnum && $sernum) { //if uid and pn/sn supplied + $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\" and partnum=\"$partnum\" and sernum=\"$sernum\""); + $checkmm = TRUE; + $mismatchqry = mysqli_query($db, "select * from parts where (uid like \"$uid\" and ((partnum !=\"$partnum\" and partnum !=\"\")or (sernum !=\"$sernum\" and sernum !=\"\"))) or ((uid not like \"$uid\" and uid not like \"\") and (partnum =\"$partnum\" and sernum =\"$sernum\")) "); - } else if ($uid && $partnum && ! $sernum ) { //if uid and pn only supplied - $partqry=mysqli_query($db,"select * from parts where uid like \"$uid\" and partnum=\"$partnum\""); - $checkmm=1; - $mismatchqry=mysqli_query($db,"select partid from parts where + } else if ($uid && $partnum && ! $sernum) { //if uid and pn only supplied + $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\" and partnum=\"$partnum\""); + $checkmm = TRUE; + $mismatchqry = mysqli_query($db, "select partid from parts where (uid like \"$uid\" and partnum !=\"$partnum\") or (uid not like \"$uid\" and partnum =\"$partnum\") "); - } else if ($uid && ! $partnum && $sernum ) { //if uid and sn only supplied - $partqry=mysqli_query($db,"select * from parts where uid like \"$uid\" and sernum=\"$sernum\""); - $checkmm=1; - $mismatchqry=mysqli_query($db,"select partid from parts where + } else if ($uid && ! $partnum && $sernum) { //if uid and sn only supplied + $partqry = mysqli_query($db, "select * from parts where uid like \"$uid\" and sernum=\"$sernum\""); + $checkmm = TRUE; + $mismatchqry = mysqli_query($db, "select partid from parts where (uid like \"$uid\" and sernum !=\"$sernum\") or (uid not like \"$uid\" and sernum =\"$sernum\") "); } else { // not enough input data supplied, so return result of 1 - $result=1; + $result = 1; } if (! $result) { if (mysqli_num_rows($partqry)) { @@ -807,9 +809,6 @@ function get_part_data($partinputdata) { if ($checkmm) { if (mysqli_num_rows($mismatchqry)) { $result=2; - //while ($mmdata=mysqli_fetch_assoc($mismatchqry)) { - //var_dump($mmdata); - //} } }