Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Whats wrong with this PHP code? (https://www.warriorforum.com/programming/1197151-whats-wrong-php-code.html)

Mrnace 26th June 2016 02:35 PM

Whats wrong with this PHP code?
 
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?

yukon 26th June 2016 02:39 PM

Re: Whats wrong with this PHP code?
 
Try mysqli_connect

Mrnace 26th June 2016 02:44 PM

Re: Whats wrong with this PHP code?
 
would I have to insert the i ever time I mention mysql?

Mrnace 26th June 2016 02:47 PM

Re: Whats wrong with this PHP code?
 
Its made no different, still shows an error.

Any other ideas?

Mrnace 26th June 2016 03:17 PM

Re: Whats wrong with this PHP code?
 
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)){

SteveJohnson 27th June 2016 07:19 AM

Re: Whats wrong with this PHP code?
 
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.

Sun Tzi 28th June 2016 06:37 AM

Re: Whats wrong with this PHP code?
 
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);
} 


Mrnace 30th June 2016 05:30 AM

Re: Whats wrong with this PHP code?
 
Quote:

Originally Posted by SteveJohnson (Post 10743434)
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.

I done my best with this and getting alot of syntax errors which I think are a little pedantic.

Im totally confused.

Mrnace 30th June 2016 05:31 AM

Re: Whats wrong with this PHP code?
 
Quote:

Originally Posted by Sun Tzi (Post 10745010)
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);
} 


How do I get that symbol?

robomedia 30th June 2016 05:57 AM

Re: Whats wrong with this PHP code?
 
Just turn off error reporting, "deprecated" isn't an error itself.
Did that code ever worked if so when did it stop? Maybe your problem is somewhere else .

zardon 18th July 2016 07:22 AM

Re: Whats wrong with this PHP code?
 
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.


All times are GMT -6. The time now is 12:59 PM.