-2

I am trying to put data in MySQL with PHP but is not showing any error but values are not entered in database too.

$query = "INSERT INTO orders (username, servicename, link, quantity, cost, date)
          VALUES('$username', '$service_name', '$link', '$quanitiy', '$cost', '$date')";
$insert=mysqli_query($db, $query);
Grant
  • 2,413
  • 2
  • 30
  • 41
TCR
  • 3
  • 3
  • 4
    **Your code is vulnerable to SQL injection and will be hacked** even if [you are escaping inputs!](https://stackoverflow.com/a/5741264/2595450) Use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead. – Spoody Apr 10 '18 at 18:49
  • You are not printing any errors, you need to use `mysqli_error()` – Spoody Apr 10 '18 at 18:50
  • See also https://xkcd.com/327/ and https://www.owasp.org/index.php/SQL_Injection – spencer7593 Apr 10 '18 at 18:59
  • hi, there was issue in mysql structure, fixed that thanks anyways – TCR Apr 10 '18 at 20:20

1 Answers1

0

I think your query should look something like that:

$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}
// create the query
$query = "INSERT INTO orders (username, servicename, link, quantity, cost, date)
          VALUES('$username', '$service_name', '$link', '$quanitiy','$cost', '$date')";
// preform the query
$insert=mysqli_query($conn, $query);
// you need to check if the insert succeeded before closing the connection
// close connection to DB
mysqli_close($conn);