php - varchar datatype doesnt show result for long entries -
this question has answer here:
- varchar data shows results selectively 2 answers
i developing application monitor ip adress activity. using lamp stack on ubuntu 12.04. in mysql database, created table 2 columns , ip , mac, both have datatype varchar. put data table , when use select * table, result
ip mac 1 2 1.10.0.0.43 00 19 78 d3 r5 ed 8.9 32.22
the middle row how expect entries come switch like.the first , 3rd put them testing purposes.
i have written php code matching , retrieval , follows
<?php $var = $_request['ip']; echo $var; mysql_connect( "localhost", "root", "mysql" ) or die("unable connect database"); mysql_select_db( "syslog" ); $result = mysql_query( "select ip,mac arp_table ip=$var" ); $row = mysql_fetch_row( $result ); print_r( $row ); ?>
when enter 1 on form ,the result ok, in form of 1 array([0]=>1[1]=>2)
, when enter 8.9, output ok well. when enter 1.10.0.0.43, output echo of variable, no array retrieved. idea of why so?
that because not using quotes around $var
. when using strings in sql need quoted such as:
select ip,mac arp_table ip='$var';
if not quoted value interpreted mysql , automatically converted (for example) integer
because value looks integer 1
/ 2
... etc..
Comments
Post a Comment