Jump to content

insert is dropping off digits


elentz

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.