0

Ive been trying to make a simple mySQL program to just check if a key is in a databse. However, i am failing, any ideas? I have tried looping around the entire database to find the value, though no luck. If anyone could shed some light on this it would be very thankful. Also The database looks like this:

VALUE

wouehourhfwfrhg

rwihewoughwourh

fw8rhfouirhushr

wrohwroghwhrwhr

And the program just checks if the input in the box is in the database.

<html>
<head>
<?php
require_once ("config.php");
function isKeyValid($key){
  $query='SELECT `Value` FROM `InviteKeys` WHERE `Used`=0';
  $response = @mysqli_query($link,$query);
  if($response)
  {
    echo($key);
    while($row = mysqli_fetch_array($response))
    {
      echo $row . "<br>";
      if($key==$row)
        return 1;
    }
    return 0;
  }
}
if(isset($_POST['submit'])){
    $key = trim($_POST['keyInput']);
    if(isKeyValid($key))
    {
      echo("KYS");
    }
    else {
      echo("Kys less");
    }
}
?>
</head>
<body>
<form action='/keyTester.php' method="post">
  <input type="text" name="keyInput" size="30" placeholder = "Username" class = "inpoot"><br>
  <input type="submit" name="submit" value="Submw">
</form>
</body>
</html>
Mattia Marziali
  • 99
  • 1
  • 1
  • 7
  • 1
    `$link` isn't in scope in your function, PHP will be trying to raise an error about this, but you're suppressing it with `@` – iainn Feb 05 '18 at 21:59
  • 1
    ^^^^^ Yes, so don't use `@` and definitely use `error_reporting(E_ALL); ini_set('display_errors', '1');` – AbraCadaver Feb 05 '18 at 22:00
  • What output **do** you get? I'm supposing it's an error that tells you that you cannot convert arrays to strings like tat, is that correct? – Stratadox Feb 05 '18 at 22:01
  • It's been working fine, i got it from the config.php – Mattia Marziali Feb 05 '18 at 22:01
  • Also @Stratadox, I get no output at all, here check for yourself http://www.tmcior.tk/keyTester.php it should respond with KYS to VPx46RG2an1IqaBD . Sorry for bad naming. – Mattia Marziali Feb 05 '18 at 22:02
  • Note: The object-oriented interface to `mysqli` is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface. Before you get too invested in the procedural style it’s worth switching over. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era when `mysqli` API was introduced and should not be used in new code. – tadman Feb 05 '18 at 22:04
  • **WARNING**: Using the error-suppressing YOLO operator (`@`) obscures problems with your code and makes debugging issues like this a whole lot more complicated. That's a tool of last resort and should only be used in exceptional circumstances. You should display an error message for the user, log a problem, initiate some kind of retry, or all of these things in conjunction. – tadman Feb 05 '18 at 22:04
  • I get a simple "Kys less" response for any input, presumable because you've left out the echo statements in the online version. – Stratadox Feb 05 '18 at 22:05
  • You're going about it all wrong; see the duplicates. – Funk Forty Niner Feb 05 '18 at 22:07

0 Answers0