Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code:
PHP
<pre><?PHP
$tabela = $_POST['tabela'];
$gracz = $_POST['gracz'];
$zmiennaIN = $_POST['zmienna'];


$con = mysqli_connect("localhost","root","") or ("Blad polaczenia: "  . mysqli_error());
if (!$con)
	die('Nie mozna polaczayc: ' . mysqli_error());
	
mysqli_select_db($con, "konta") or die ("Nie mozna wczytac bazy danych" . mysqli_error());

$zmiennaOUT = mysqli_result(mysqli_query($con, "SELECT '".$zmiennaIN."' FROM '".$tabela."' WHERE login='".$gracz."'"),0);
 
die ($zmiennaOUT);

?>



What I have tried:

Error:
Fatal error: Uncaught Error: Call to undefined function mysqli_result() in C:\xampp\htdocs\unity\odczytDanych.php:13 Stack trace: #0 {main} thrown in C:\xampp\htdocs\unity\odczytDanych.php on line 13
Posted
Updated 4-Jul-22 0:43am
Comments
Member 15695861 4-Jul-22 4:27am    
I think on this line is problem:

$zmiennaOUT = mysqli_result(mysqli_query($con, "SELECT '".$zmiennaIN."' FROM '".$tabela."' WHERE login='".$gracz."'"),0);

I don't believe there's a function called mysqli_result, instead that appears to be a class that PHP can return. Instead, you should use a function like PHP: mysqli_result::fetch_array - Manual[^] which will return the results in an array.
 
Share this answer
 
Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
 
Share this answer
 
This line is wrong:
PHP
$zmiennaOUT = mysqli_result(mysqli_query($con, "SELECT '".$zmiennaIN."' FROM '".$tabela."' WHERE login='".$gracz."'"),0);

it should be:
PHP
$zmiennaOUT = mysqli_query($con, "SELECT '".$zmiennaIN."' FROM '".$tabela."' WHERE login='".$gracz."'");

Ignoring the fact that you should never use string concatenation to build SQL queries.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900