Your script has at least 5 errors
First, this line is wrong:
$resource = mysqli_query($sql) or die(mysqli_error($conexao));
Another strange thing is that for the connection you have two variables $conexao
and $link
, one of them must be wrong.
Here you set it $resource
, but I think what I wanted was $result
Besides you’re past the result of a mysqli_query
in another:
$sql = mysqli_query( $link,'SELECT * FROM files id = 2');
$resource = mysqli_query($sql) or die(mysqli_error($conexao));
Another mistake is that the WHERE
in your SELECT:
SELECT * FROM files id = 2
Should be:
SELECT * FROM files WHERE id = 2
What doesn’t make any sense
And you’re mixing the old API’s mysql
with the new API called mysqli
, the correct would be:
favorite
I know you probably have other similar answers, but none of them I thought you needed. In the database I have a table with id, name, version, upload and size. I just need to get the version of the file I selected by SELECT the following code:
<?php
$num = 1;
if($num == 1){
$result = mysqli_query($link, 'SELECT * FROM files WHERE id = 2') or die(mysqli_error($link));
while ($ln = mysqli_fetch_array($result, MYSQLI_NUM)) {
...
}
mysqli_free_result($result);
A very simple example of mysqli
<?php
//$link é a variavel da "conexão"
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* Verifica erros */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit;
}
$result = mysqli_query($link, 'SELECT ...') or die(mysqli_error($link));
/* array numerica */
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
/* array associativa */
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
printf ("%s (%s)\n", $row["Nome"], $row["Sobrenome"]);
}
/* associativa e numerica */
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
printf ("%s (%s)\n", $row[0], $row["Sobrenome"]);
}
/* libera a memoria */
mysqli_free_result($result);
/* fecha a conexão */
mysqli_close($link);
Read the documentation
a hint, do not go around doing things randomly, documentations exist to be used, follow the links:
mysqli_fetch_array
; i missed an i– bfavaretto
and
$result
there is no?– bfavaretto
I have already checked and I have just corrected, but what would be the right way to put Select?
– Alis
SELECT * FROM files WHERE id = 2
. Missed the WHERE– bfavaretto
but it does not have " ", or ' '
– Alis