I am trying to write a PHP script with MySQLi to query a database.
Id like it if user input can be checked against the database and then return the result from the column mate if there is a row in the root column of the normal_verbs table at the input.
So, if the user input is something like “foobar” and the root column is “foo”, I would like it to see “foo” in “foobar” and return that “pairing” value on this line.
I cannot make the request work the way I want. The one I use below is basically just a placeholder. I do not quite understand why this is not working.
What I'm trying is:
function db_connect() { static $connection; if(!isset($connection)) { $connection = mysqli_connect('localhost','user','password','Verb_Bank'); } if($connection === false) { return mysqli_connect_error(); } return $connection; } function db_query($query) { $connection = db_connect(); $result = mysqli_query($connection,$query); return $result; } function db_quote($value) { $connection = db_connect(); return "'" . mysqli_real_escape_string($connection,$value) . "'"; } $m= db_query("SELECT `conjugation` from normal_verbs where `root` in (" . $y . ")"); if($m === false) {
This does not give me any errors, so I think it connects to the database.
EDIT2: I was wrong. I lost something obvious due to a misunderstanding of MySQLi and edited the code accordingly. So the above code works in the sense that it connects to the database and returns the result, but I still can’t say that I want it to do what I want.
source share