Jump to content
elentz

insert is dropping off digits

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.

Share this post


Link to post
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.

 

Edited by mac_gyver

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

A MAC address is not a number. The column should not be a number type.

  • Great Answer 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.