How to insert mail data in mysql db with php?

I have been trying to fix this problem for several hours and donโ€™t know why this is not working. I am trying to send an http message with a Qt application and use this as my php script:

<?php
$con=mysqli_connect("*.mysql.eu2.*.com:3306","*****","****","****");

if (mysqli_connect_errno($con))
{
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$price = filter_input(INPUT_POST, 'price', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
$stock= filter_input(INPUT_POST, 'stock', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);

  $currentid = mysqli_insert_id();

  if (trim($id) == '') {
    exit('id cannot be empty!');
  }
  if (trim($price) == '') {
    exit('price cannot be empty!');
  }
  if (trim($type) == '') {
    exit('type cannot be empty!');
  }
  if (trim($stock ) == '') {
    exit('stock cannot be empty!');
  }

  $result = "insert into ammo (ammoType,storeId,ammoStock,ammoPrice) VALUES ('".$type."','".$id."','".$stock."','".$price."');";

   mysqli_query($result) or die("Could not insert data");



mysqli_close($con);
?>

I was at some point until the moment when I was getting success, but then the values โ€‹โ€‹did not actually show up in my db. Thanks, David

+4
source share
1 answer

Firstly, you are not connecting to your request.

mysqli_query($result)

This function requires first 2 parameters, as well as a connection to the database.

mysqli_query($con,$result)

Read the manual: http://php.net/manual/en/mysqli.query.php

. , HTML-, POST, .

undefined index, , .

, .

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: .

or die("Could not insert data");

or die(mysqli_error($con));

.

N.B.:

MySQL , Jack Bar & Grill, .

  • , .
+4

Source: https://habr.com/ru/post/1615982/


All Articles