Closed Thread
Thread Tools Search this Thread
Unread 26th Jun 2016, 02:35 PM   #1
HyperActive Warrior
Registered Member
War Room Member
 
Join Date: 2013
Location: Cardiff, UK
Posts: 357
Thanks: 16
Thanked 15 Times in 12 Posts
Default
Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

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?
Mrnace is offline  
Unread 26th Jun 2016, 02:39 PM   #2
Banned
 
Join Date: 2010
Posts: 22,774
Thanks: 2,708
Thanked 11,312 Times in 7,455 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

Try mysqli_connect
yukon is offline  
Unread 26th Jun 2016, 02:44 PM   #3
HyperActive Warrior
Registered Member
War Room Member
 
Join Date: 2013
Location: Cardiff, UK
Posts: 357
Thanks: 16
Thanked 15 Times in 12 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

would I have to insert the i ever time I mention mysql?
Mrnace is offline  
Unread 26th Jun 2016, 02:47 PM   #4
HyperActive Warrior
Registered Member
War Room Member
 
Join Date: 2013
Location: Cardiff, UK
Posts: 357
Thanks: 16
Thanked 15 Times in 12 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

Its made no different, still shows an error.

Any other ideas?
Mrnace is offline  
Unread 26th Jun 2016, 03:17 PM   #5
HyperActive Warrior
Registered Member
War Room Member
 
Join Date: 2013
Location: Cardiff, UK
Posts: 357
Thanks: 16
Thanked 15 Times in 12 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

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)){
Mrnace is offline  
Unread 27th Jun 2016, 07:19 AM   #6
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

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.

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
Unread 28th Jun 2016, 06:37 AM   #7
Warrior Member
 
Sun Tzi's Avatar
 
Join Date: 2016
Posts: 10
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

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);
} 

Every journey begins with a small step.

Last edited on 28th Jun 2016 at 06:39 AM. Reason: Buggy forum software
Sun Tzi is offline  
Unread 30th Jun 2016, 05:30 AM   #8
HyperActive Warrior
Registered Member
War Room Member
 
Join Date: 2013
Location: Cardiff, UK
Posts: 357
Thanks: 16
Thanked 15 Times in 12 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

Originally Posted by SteveJohnson View Post

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 is offline  
Unread 30th Jun 2016, 05:31 AM   #9
HyperActive Warrior
Registered Member
War Room Member
 
Join Date: 2013
Location: Cardiff, UK
Posts: 357
Thanks: 16
Thanked 15 Times in 12 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

Originally Posted by Sun Tzi View Post

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?
Mrnace is offline  
Unread 30th Jun 2016, 05:57 AM   #10
Active Warrior
 
Join Date: 2014
Posts: 84
Thanks: 5
Thanked 11 Times in 10 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

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 .
robomedia is offline  
Unread 18th Jul 2016, 07:22 AM   #11
HyperActive Warrior
 
zardon's Avatar
 
Join Date: 2010
Location: Newcastle, UK
Posts: 202
Thanks: 24
Thanked 16 Times in 16 Posts
Default
Re: Whats wrong with this PHP code?
Share on: 
fb share twitter share gplus share more share

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.
zardon is offline  
Closed Thread


Bookmarks

Tags
code, php, wrong

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 01:03 PM.