PHP-MySQL form with 1 field input validation -
in php got simple form 1 field has validated , string stripped both sides. string keep characters , want match if stripped string in mysql db. if exists in db input string db table, if not discard it.
the problem enter validated if statement true , inserted database. has insert when if statement true, not everytime. got working without string stripping when strip string crap cant working again...
this code string strip , validates true
... $txt=substr($_post[zz_id],12,-1); $test = mysql_query("select zzcode zzcodes zzcode='$txt'"); $row = mysql_fetch_array($test); if ($row['zzcode']== $txt) $sql="insert data values ('$_post[zz_id]','$_post[id]', timestamp(8))"; else echo "zz code error"; echo "<br />"; echo $txt; if (!mysql_query($sql,$con)) { die('error: ' . mysql_error()); } mysql_close($con) ... here block of code without string strip works:
... $test = mysql_query("select zzcode zzcodes zzcode='$_post[zz_id]'"); $row = mysql_fetch_array($test); if ($row['zzcode']== $_post[zz_id]) $sql="insert data values ('$_post[zz_id]','$_post[id]', timestamp(8))"; else echo "zz koodi ei saa sisestada"; echo "<br />"; if (!mysql_query($sql,$con)) { die('error: ' . mysql_error()); } mysql_close($con) ...
if want compare strings suggest use string comparison function such strcmp. know more strcmp visit strcmp - php manual.
this function return 0 if 2 strings equal. comparison case sensitive.
Comments
Post a Comment