Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-21-2008, 03:14 PM MySQL Error 22
[B]lackwater's Avatar
Novice Talker

Posts: 14
Trades: 0
Have a website with some PHP scripting in it. I get a MySQL error in it. I've used this code before on other websites, the exact same code as in copy-paste. For some reason it does not work.

Code:
Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /homepages/31/d231284211/htdocs/home/editor/editor.php on line 22
__________________
Code:
if( $hungry ) { eat(); } 
    else { sleep(); }
[B]lackwater is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-21-2008, 04:34 PM Re: MySQL Error 22
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Try not using mysqli another words your mysql server may not support that...Use mysql (without the i ) and that may work.

Not all servers will work the same, you need to check the configuration of the server before making your decision on what server you want to use. mySQL 2 mySQL doesn't mean it's all going to be the same.

Good luck
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 10-21-2008 at 04:37 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 10-21-2008, 06:14 PM Re: MySQL Error 22
[B]lackwater's Avatar
Novice Talker

Posts: 14
Trades: 0
Each time I've used this script it has been on the same server. I've been doing this long enough to know that you need to check which version of MySQL and PHP you are running and to make sure that the mysqli extension has been enabled.

The client's host is the same as mine, I've double checked the .htaccess on the site to make sure that the latest version of PHP and MySQL are being run.
__________________
Code:
if( $hungry ) { eat(); } 
    else { sleep(); }
[B]lackwater is offline
Reply With Quote
View Public Profile
 
Old 10-22-2008, 02:04 AM Re: MySQL Error 22
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
All local mind readers are fired. Show the code.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-22-2008, 05:30 PM Re: MySQL Error 22
[B]lackwater's Avatar
Novice Talker

Posts: 14
Trades: 0
Code:
<?php
$DBConnect = mysqli_connect('db18.perfora.net','<removed>','<removed>','<removed>');

$SQL = "SELECT * FROM Content WHERE Page = 'Staff'";
$AboutUsResult = mysqli_query($DBConnect, $SQL);

$About_Content = mysqli_fetch_array($AboutUsResult);
$Staff = $About_Content[0];


$SQL = "SELECT * FROM Content WHERE Page = 'Staff'";
$StaffResult = mysqli_query($DBConnect, $SQL);

$Staff_Content = mysqli_fetch_array($StaffResult);
$Staff = $Staff_Content[0];

$SQL = "SELECT * FROM counter";
$QueryResult = mysqli_query($DBConnect, $SQL);

$PageVist = mysqli_fetch_array($QueryResult);
$PageVists = $PageVist[0];

?>
Note: the $PageVisit variable works fine. the mysqli_fetch_array() works perfectly for it as the number is actually displayed. However for the rest of them it does not work.
__________________
Code:
if( $hungry ) { eat(); } 
    else { sleep(); }

Last edited by chrishirst; 10-23-2008 at 04:00 AM.. Reason: MySQL Login details removed
[B]lackwater is offline
Reply With Quote
View Public Profile
 
Old 10-23-2008, 04:03 AM Re: MySQL Error 22
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's not usually considered a good idea to leave usernames and passwords to your database visible in a public forum.

It's been there for almost 11 hours now, I would suggest changing them pretty quickly!
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-23-2008, 04:19 AM Re: MySQL Error 22
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
And which of these lines causes an error?

Also add some debug code after each mysqli_query() like the following:

PHP Code:
$res mysqli_query($connection$sql);
if (!
$res) {
   echo 
mysqli_error();
}
else {
   
// fetch_data

This will show you what exactly is wrong with your query.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-23-2008, 12:04 PM Re: MySQL Error 22
[B]lackwater's Avatar
Novice Talker

Posts: 14
Trades: 0
Quote:
Originally Posted by chrishirst View Post
It's not usually considered a good idea to leave usernames and passwords to your database visible in a public forum.

It's been there for almost 11 hours now, I would suggest changing them pretty quickly!
Thank you for catching that!! I thought I had removed all of the sensitive information from the code. I appreciate you removing it!!

Code:
22: $About_Content = mysqli_fetch_array($AboutUsResult);
$Staff = $About_Content[0];


$SQL = "SELECT * FROM Content WHERE Page = 'Staff'";
$StaffResult = mysqli_query($DBConnect, $SQL);

29: $Staff_Content = mysqli_fetch_array($StaffResult);
$Staff = $Staff_Content[0];
The Error indicates that the problems are located on lines 22 and 29. I have placed the line numbers in the code to indicate the lines in question.
__________________
Code:
if( $hungry ) { eat(); } 
    else { sleep(); }
[B]lackwater is offline
Reply With Quote
View Public Profile
 
Old 10-23-2008, 01:15 PM Re: MySQL Error 22
Experienced Talker

Posts: 41
Name: Jabis Sevon
Location: Tampere, Finland
Trades: 0
Quote:
Originally Posted by [b]lackwater View Post
Code:
Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /homepages/31/d231284211/htdocs/home/editor/editor.php on line 22
You have the error stated right in front of you, you're passing a boolean (true|false) parameter to the fetch_array instead of an SQL resultset from the db.

Try something like this
PHP Code:
$DBConnect mysqli_connect("host""user""password""db");
/* first check the connection, do this always! */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

$sql "SELECT * FROM Content WHERE Page = 'Staff'";
/* try it like this */
if ($AboutUsResult mysqli_query($DBConnect$sql)) {

/* return the numeric array */
$row mysqli_fetch_array($AboutUsResultMYSQLI_NUM);
printf ("%s (%s)\n"$row[0]);  

} else {
printf("Error: %s\n"mysqli_error($DBConnect));
}
 
/* when you're done free the resultset */
mysqli_free_result($AboutUsResult);

/* close connection */
mysqli_close($DBConnect); 
The other possible thing could be that your query doesn't return a resultset, to think of it, but to test it, you should do like follows:
PHP Code:
if(mysqli_query($DBConnect$sql) === TRUE) {
 
printf("successfully queried.\n");
} else {
printf("query failed.\n");


Last edited by jabis; 10-23-2008 at 01:25 PM.. Reason: **** typos
jabis is offline
Reply With Quote
View Public Profile Visit jabis's homepage!
 
Reply     « Reply to MySQL Error 22
 

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47023 seconds with 12 queries