Problem to save record with PHP

0

I must keep a numeric record (units that come in a box) but it is not saving me I do the following.

if(isset($_POST['act'])) {
    if($_POST['act'] == '1') {
        if(!isset($_POST['name']) || !isset($_POST['descrp']) || !isset($_POST['cat']) || !isset($_POST['qty']) || !isset($_POST['price']) || !isset($_POST['qty2']))
            die('wrong');
        if($_POST['name'] == '' || $_POST['cat'] == '' || $_POST['price'] == '')
            die('wrong');

        $name = $_POST['name'];
        $descrp = $_POST['descrp'];
        $cat = $_POST['cat'];
        $qty = $_POST['qty'];
        $qty2 = $_POST['qty2'];

Unidad por caja:<br />
<input type="text" name="item-qty2" class="ni-small" placeholder="0" />

Then

var qty2 = $('input[name=item-qty2]').val();

$.post('new-item.php', {
            'act':'1',
            'name':name,
            'descrp':desc,
            'cat':cat,
            'qty':qty,
            'price':price,
            'qty2':qty2
        }, function(data) {
            if(data == '1') {
                alert('Referencia creada correctamente');
                location.href = 'new-item.php';
            }else{
                alert('Error 11. Por favor, vuelva a intentarlo');
                return false;
            }
        });

I missed the alert ('Error 11. Please try again');

Code in: inc / items_core.php - new_item ()

public function new_item($name, $desc, $cat, $qty, $price, $qty2) {
    $name = stripslashes($name);
    $desc = stripslashes($desc);
    $cat = stripslashes($cat);
    $qty = stripslashes($qty);
    $qty2 = stripslashes($qty2);
    $price = stripslashes($price);
    $date = date('Y-m-d');
    if($qty == '')
        $qty = 0;

    //Pone el texto ingresado en mayusculas 
    //Para guardar en mayusculas en la DB
    $name = strtoupper($name); 

    $prepared = $this->prepare("INSERT INTO invento_items(name,descrp,category,qty,price,date_added,qty2) VALUES(?,?,?,?,?,?)", 'new_item()');
    $this->bind_param($prepared->bind_param('ssiiis', $name, $desc, $cat, $qty, $price, $date, $qty2), 'new_item()');
    $this->execute($prepared, 'new_item()');

    return true;
}
    
asked by Saul Salazar 11.09.2018 в 16:36
source

1 answer

1
  var qty2 = $('input[name=item-qty2]').val();

  $.post('new-item.php', {
        'act':'1',
        'name':name,
        'descrp':desc,
        'cat':cat,
        'qty':qty,
        'price':price,
        'qty2':qty2
    }, function(data) {
        if(data) {
            alert('Referencia creada correctamente');
            location.href = 'new-item.php';
        }else{
            alert('Error 11. Por favor, vuelva a intentarlo');
            return false;
        }
    });

Put the alert if in the following way:

if(data){ /*code*/ }else{  /*code*/ }

Evaluate only "data" without the operator "=" and check if on the server side it prints "1"

    
answered by 11.09.2018 / 17:12
source