How to escape mysql blank and duplicate data using php -


i using code send data mysql database , functioning though users sending blank data , duplicating too.

<?php    require "conn.php";   $lostidno = $_post ["lostidno"];   $phonenol = $_post ["phonenol"];    $mysql_qry = "insert lostdb.lost (lostidno, phonenol) values ('$lostidno', '$phonenol')";      if ($conn->query($mysql_qry) === true)    {     echo "information recieved!";   }   else     echo "sorry! error occured:" . $mysql_qry . "br" . $conn->error;    $conn->close();  ?> 

how prevent this?

you can use trim function remove spaces @ beginning , ending of string. after able check if 2 parameters aren't empty:

<?php  require "conn.php"; $lostidno = trim($_post["lostidno"]); $phonenol = trim($_post["phonenol"]);  if(!empty($lostidno) && !empty($phonenol)) {     $mysql_qry = "insert lostdb.lost (lostidno, phonenol) values ('$lostidno', '$phonenol')";        if ($conn->query($mysql_qry) === true) {         echo "information recieved!";     }     else {         echo "sorry! error occured:" . $mysql_qry . "br" . $conn->error;     }      $conn->close(); } ?> 

you should have @ this prevent sql injections.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -