Whats wrong with this PHP code?

by 10 replies
12
mysql_connect ("localhost", "nathan_userblog", "");

I've removed the password, but I get an error saying its depricated.

It reads below -

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home1/nathan/public_html/Blog.php on line 2

How to I correct this?
#programming #code #php #wrong
  • Banned
    Try mysqli_connect
  • would I have to insert the i ever time I mention mysql?
  • Its made no different, still shows an error.

    Any other ideas?
  • Getting these errors now -

    Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/nathan/public_html/Blog.php on line 50

    Line 50 -

    $sql = mysqli_query("SELECT * FROM blog1data ORDER BY id DESC");

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home1/nathan/public_html/Blog.php on line 51

    Line 51 -

    while ($row = mysqli_fetch_array ($mysqli_result, $sql)){
  • See this page to learn how to use PHP mysqli library: PHP mysqli_fetch_array() Function

    Your questions are answered there, just have a look at the code and compare it to what you're doing.
    • [1] reply
    • I done my best with this and getting alot of syntax errors which I think are a little pedantic.

      Im totally confused.
  • [DELETED]
    • [1] reply
    • To show no errors or warnings type
      PHP Code:
      error_reporting(0); 
      For the message;
      Code:
      Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/nathan/public_html/Blog.php on line 50
      YOU MUST SUBTITUDE THE §-Sign WITH THE $-Sign, BECAUSE OF THE FORUMS SOFTWARE WHITCH REMOVES THE WHOLE VARIABLE IF IT BEGINS WITH $


      Fix for line 50:
      PHP Code:
      §result = mysqli_query(§connection, §query); //§connection = result of mysqli_connect (must be from type ressource) 
      Fix for line 51
      PHP Code:
      while( §row = mysqli_fetch(§result)) {
        
      //e.g. print_r(§row);
      } 
      Cleanest version
      PHP Code:
      while((§row =mysqli_fetch(§result)) !== null) {
        
      //e.g. print_r(§row);
      } 
      • [1] reply
  • Change the PHP ini file to only report errors and ignore warnings.
    If you want you can put @ in front of php commands like mysql connect to prevent it outputting those kind of warnings.
  • [DELETED]
    • [ 1 ] Thanks
  • Banned
    [DELETED]

Next Topics on Trending Feed