A
A
Angry Negro2017-10-17 00:24:03
PHP
Angry Negro, 2017-10-17 00:24:03

How to compare value with value from MySQL database?

Actually, there is a base with keys. The user enters one of the keys in the field, it is submitted in the form and in the end I want it to be validated. Is it in the database. I did it as indicated below in the image - I tried to compare the entered number with what is in the database. Nothing happened .. How can this be implemented?

<?php

$mysqli = new mysqli ("localhost", "ПОЛЬЗОВАТЕЛЬ", "ПАРОЛЬ", "БАЗА");
$mysqli->query ("SET NAMES 'utf8'");
$result_set = $mysqli->query ("SELECT `promo_codes` FROM  `promo` LIMIT 0 , 30");

function printResult ($result_set){
  while (($row = $result_set->fetch_assoc()) != false) {
    print_r ($row);
    echo "<br />";
  }
echo "Кол-во: ".$result_set->num_rows."<br /><br />";
}

function promoone ($promoone){
if(isset($_POST["done"])){
if ($_POST["promo"] == ""){
echo "<div class='verify'>";
echo "Введите промокод.";
echo "</div>";
}

if ($_POST["promo"] == "ЗДЕСЬ СРАВНИВАЕМ СО ЗНАЧЕНИЕМ ИЗ БАЗЫ")
  echo "Это сработало";
  else {
    echo "Полный провал.";
  }

}
}
$mysqli->close ();
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
darksladen, 2017-10-17
@TOA

$stmt = $mysqli->prepare("SELECT promo_codes FROM promo WHERE promo_codes=? LIMIT 0, 1");

$promo_codes = $_POST["promo"];
$stmt->bind_param('s', $promo_codes);
$stmt->execute();

$result = $stmt->get_result();

if ($promo_code = $result->fetch_row()) {
    var_dump($promo_code);
    echo 'Промокод найден!';   
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question