luka032 luka032 -5 years ago 183
SQL Question

Codeigniter php: SQL injection prevent

I've finished one application, but while developing haven't checked about sql injections and now at the end, i need to fix this little issue.

Here's my code, how could i on easiest way fix this to prevent sql injection (is there any function just to format my username, password parameters, not to change my code).

public function getArtistByUsernameByPassword($username, $password) {
$query = $this->db->query("SELECT * FROM artists WHERE username = '$username' AND password = ' $password'");
if ($query->num_rows() > 0) {
return $query->row_array();
return null;

Thanks in advance!

Answer Source

Use Codeigniter's query builder class.

So your code would look like this.

$query = $this->db->get_where('artists', array('username' => $username, 'password' => $password));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download