0

I'm getting a deprecated error with the following code

require 'dbconfig.php';
function checkuser($fuid,$ffname,$femail){
        $check = mysql_query("select * from Users where Fuid='$fuid'");
    $check = mysql_num_rows($check);
    if (empty($check)) { // if new user . Insert a new record       
    $query = "INSERT INTO Users (Fuid,Ffname,Femail) VALUES ('$fuid','$ffname','$femail')";
    mysql_query($query);    
    } else {   // If Returned user . update the user record     
    $query = "UPDATE Users SET Ffname='$ffname', Femail='$femail' where Fuid='$fuid'";
    mysql_query($query);
    }
}

but every time I try to use mysqli I get a error

Warning: Cannot modify header information - headers already sent by

what should I do?

  • Fix your code? That would be step one. There is absolutely no reason that changing from mysql_ to mysqli_ should give you header-errors, unless you have errors being output before a header - btw, nothing in the provided code shows any header-info, hence it's useless for us to look through. Changing directly from mysql_ to mysqli_ won't help the real problem either, which is non-prepared queries. Read up on "prepared queries using mysqli", do decent error-handling, and/or post the full code here. – junkfoodjunkie Apr 16 '17 at 19:40
  • As mysql_* was deprecated in PHP 5.5 (please refer to [PHP doc](http://php.net/manual/en/function.mysql-connect.php)) you should **really** consider using [PPS : Prepared Parameterized Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). This will help [Preventing SQL injection](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). But this has nothing to do with the `Warning: headers already sent` – OldPadawan Apr 16 '17 at 19:42
  • `mysqli` or `mysql`? Include the notice and your actual code, if you are using `mysqli`. This code is using `mysql_`. – chris85 Apr 16 '17 at 20:14
  • Possible duplicate of [Why shouldn't I use mysql\_\* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – chris85 Apr 16 '17 at 20:16

1 Answers1

0

Warning. This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

mysqli_connect() PDO::__construct()

http://php.net/manual/en/function.mysql-connect.php

Cannot modify header information - This error has nothing to do with databases.

Community
  • 1
  • 1
RoboNoob
  • 121
  • 4
  • The error notice is output. So `This error has nothing to do with databases.` isn't entirely true. – chris85 Apr 16 '17 at 20:15