Jump to content

[SOLVED] mysqli_fetch_array()


The Little Guy

Recommended Posts

<?php
$sql = mysqli_query($db,"SELECT * FROM web_search WHERE RLIKE '%{$_GET['q']}%'"); # Line 13
$row = mysqli_fetch_array($sql,MYSQLI_ASSOC); # Line 14
?>

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\search\search.php on line 14

 

Anyone know what that means?

Link to comment
Share on other sites

Well what if someone posted something like

...

script.php?q=' UNION ALL evil things --

 

then your query would read

 

SELECT * FROM web_search WHERE RLIKE '%' UNION ALL evil things -- %'

 

and they could add whatever they wanted to your query...

to fix this you would want to use mysqli_real_escape_string() (or a similar function) to escape all the characters like the ' I used above

 

<?php
$query = $_GET['q'];
if(get_magic_quotes_gpc()) 
{
   $query = stripslashes($query); // pull off the slashes that magic_quotes added
}
$query = mysqli_real_escape_string($connection, $result);

$result = mysqli_query($connection, "SELECT * FROM table WHERE foo = '$bar'") or die(mysqli_error($connection));
?>

 

http://www.php.net/mysqli_real_escape_string

Link to comment
Share on other sites

no, no the only insecure part of his script is the fact that he used $_GET['q'] directly in his query, it has nothing to do with whether you are using the mysqli or mysql functions.

 

Both the things you posted are secure. (The second one is actually incorrect syntax, mysqli wants a connection identifier in the query function.)

 

the mysql functions are just as vulnerable to sql injection as mysqli when they're used in this way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.