See i'm receiving the data from the form in POST method.
<form action="<?php $_SERVER['PHP_SELF']?>" method="POST">
Name: <input type="text" name="username" />
<button type="submit" name="dataSent"> Submit </button>
</form>
//Database connection. if you are in localhost the password is nothing.
<?php
define("HOSTNAME","localhost");
define("USERNAME","root");
define("PASSWORD","");
define("DBNAME","here your database name");
$conn mysqli_connect(HOSTNAME,USERNAME,PASSWORD,DBNAME);
?>
//php data receiving
<?php
if ( isset($_POST['dataSent']) ) {
$username = mysqli_real_escape_string($conn, $_POST['username'] );
echo $username;
}
?>
Now it should be work.
mysqli_real_escape_string(para 1, para 2 ) we can not receive data whithout including Databse connection inside mysqli_real_escape_string();
it receives two parameter.
1- is Database connection that not allow html special character to enter in Databse for SQL injection.
2- is receives data from form.
Thank's