0

I am not using localhost and I tried my best, as a newer to PHP, to insert data to SQL but I was unsuccessful.

The codes are as follows:

<?php
$host= "AAAA";
$user= "AAAA";
$pass= "AAAA";
$db= "AAAA";

$x1 = $_POST['X1'];
$x2 = $_POST['X2'];
$y1 = $_POST['Y1'];
$y2 = $_POST['Y2'];

$con=mysqli_connect($host,$user,$pass,$db);
$sql = "INSERT INTO table (X1, X2, Y1, Y2) values ('$x1', '$x2', '$y1', '$y2')";
$result = mysqli_query($con, $sql); // execute the query
?>

I want to insert data into SQL, but not sure why I do not get into it. I do not get any error in the form, but When I check SQL, I cant see the data that I have entred.

user1946911
  • 97
  • 1
  • 6
  • Check the success of `mysqli_query`. Also, your code is wide open to SQL injection, you should use a prepared statement. See https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – Barmar Apr 08 '20 at 18:35
  • Try adding some error reporting. https://www.php.net/manual/en/mysqli.error.php or even the connection could have failed, https://www.php.net/manual/en/mysqli.connect-error.php – user3783243 Apr 08 '20 at 18:35
  • See https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments for error checking. – Barmar Apr 08 '20 at 18:35
  • I have updated, mysqli_query give me the same outcome, i.e., data are not appeared in sql – user1946911 Apr 08 '20 at 18:42
  • I have used this before $Con= mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); but I did not get error – user1946911 Apr 08 '20 at 18:49

0 Answers0