elentz Posted June 26, 2018 Share Posted June 26, 2018 I have a page that I use to scan (with a barcode scanner) a series of barcodes for mac addresses. The page is this code <form action="insert.php" method="post" id="phoneEntry"> <fieldset> <legend><h3>Phone MAC Entry:</h3></legend> <label for="phoneEntry_dealerName">Select Dealer</label> <select name="id" id="phoneEntry_dealerName">'; while ($dealer = $dealers->fetch_assoc()) echo ' <option value="', $dealer['id'], '">', $dealer['dealername'], '</option>'; echo ' </select> <label for="macEntry_hostedLocation">Enter the Location IP:</label> <input type="text" name="location"><br> <label for="macEntry_address">Input the MAC address:</label> <textarea name="mac" id="macEntry_address"> </textarea> <button>Save</button> </fieldset> </form>'; I scan into the text area and the MAC is much like this : 80828704B0EE I scanned in 14 different barcodes and in the database they were all shortened on the back bu 4 digits. Here is the insert.php code: Scanning the same barcode it is formatted and of the correct length in notepad+ $dealerid= "$_POST[id]"; $location= "$_POST[location]"; include('/var/www/html/hosted/index.html'); require('/var/www/html/hosted/utils/connect.php'); $stmt1 = $link->prepare(' INSERT INTO phones ( dealerid, location, mac ) VALUES ( ?, ?, ? ) '); $macList = preg_split('/[\s,]+/', $_POST['mac']); $stmt1->bind_param('iss', $dealerid, $location, $mac); foreach ($macList as $mac) $stmt1->execute(); So I am thinking that the issue is somewhere in the preg_split but I don't see it. I also need to save the same MAC address into the same table (different field) in this format 80:82:87:04:B0:EE I need to eventually run a report on both formats of each MAC entry. Thanks for any insight anyone might be able to give. Quote Link to comment https://forums.phpfreaks.com/topic/307404-insert-is-dropping-off-digits/ Share on other sites More sharing options...
mac_gyver Posted June 26, 2018 Share Posted June 26, 2018 (edited) Quote So I am thinking that the issue is somewhere in the preg_split but I don't see it. the preg_split isn't the problem and you could echo the $mac value inside the loop to know for sure. the mac database column is most likely defined as an integer and the values are being truncated at the first non-numerical character. another possibility is that the column is a character type, but it is not long enough to hold the data. Edited June 26, 2018 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/307404-insert-is-dropping-off-digits/#findComment-1559087 Share on other sites More sharing options...
elentz Posted June 27, 2018 Author Share Posted June 27, 2018 Hi Thanks for the reply. I set the Mac DB column as a biginit, initially it was set as varchar with a length of 30. I will see if I can echo the $mac and see what is going on. Quote Link to comment https://forums.phpfreaks.com/topic/307404-insert-is-dropping-off-digits/#findComment-1559089 Share on other sites More sharing options...
requinix Posted June 27, 2018 Share Posted June 27, 2018 A MAC address is not a number. The column should not be a number type. 1 Quote Link to comment https://forums.phpfreaks.com/topic/307404-insert-is-dropping-off-digits/#findComment-1559092 Share on other sites More sharing options...
elentz Posted June 27, 2018 Author Share Posted June 27, 2018 I changed the field to a text field and it appears to be working the way I need it now. I still have learning to do! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/307404-insert-is-dropping-off-digits/#findComment-1559113 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.