0

I am sending data from android to php and then to database but my insert query is not working.I can't find what the problem is it always print " could not register ".I have checked my table database as well as my variable are correctly posting from android.Below is the code.

if  (isset($_POST)){

define('HOST','127.0.0.1'); 
define('USER','root');
define('PASS','');
define('DB','medicine');   // database
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');


$email = $_POST['email'];
$name = $_POST['name'];
$phone= $_POST['phone'];
$password=$_POST['password'];
$cnic=$_POST['cnic'];
$address=$_POST['address'];
 // Variables are successfully posted


$email = mysql_real_escape_string($email);
$name = mysql_real_escape_string($name);
$phone = mysql_real_escape_string($phone);
$password = mysql_real_escape_string($password);
$cnic = mysql_real_escape_string($cnic);
$address = mysql_real_escape_string($address);

$sql = "INSERT INTO userregister (email,name,phone,password,cnic,address) VALUES ('$email','$name','$phone','$password','$cnic','$address')";

if(mysqli_query($con,$sql))
{
    echo "Successfully Registered";
}
else
{
    echo "Could not register";
}
  • 1
    Learn about prepared Statements to prevent SQL injection. Note `mysql_real_escape_string(` does not prevent SQL injection – Jens Jun 09 '17 at 11:25
  • 1
    use `mysqli_error() `to get the error message and share it to us. `echo "Could not Register: Because: ".mysqli_error($con); ` – Jens Jun 09 '17 at 11:26
  • because your error message is not useful – Masivuye Cokile Jun 09 '17 at 11:26
  • @Jens Thanks a lot issue resolved didn't know about mysqli_error function().After using it tells me the error, I have put the wrong variable name in query. – Nabeel Ayub Jun 09 '17 at 11:36

0 Answers0