There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Mysql_query problem


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
sidekick007's Avatar
Junior Member with 7 posts.
 
Join Date: Sep 2007
Experience: Intermediate
07-Jul-2008, 08:34 PM #1
Mysql_query problem
Hi everyone
I want to install a script, followed all the pre-install instructions but the minute I click install.php, I get this error message: "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\www\www.test4.co.za\....\lang\lang.php on line 35" on lines 35 and 57.
Here is the full scritpt code, with lines 35 & 57 in bold:
"<?php

//if(!empty($_GET)) extract($_GET);
//if(!empty($_POST)) extract($_POST);

if (isset($_REQUEST['lang'])) {
$sql = "SELECT * FROM lang WHERE `lang_code`='".$_REQUEST['lang']."'";
$result = mysql_query($sql, $jb_mysql_link) or die (mysql_error());
if (mysql_num_rows($result)>0) {
$_SESSION["LANG"] = strtoupper($_REQUEST["lang"]);
// save the requested language
setcookie("SAVED_LANG", strtoupper($_REQUEST["lang"]), 2147483647);

} else {

$sql = "SELECT * FROM lang WHERE `is_default`='Y'";
$result = mysql_query($sql, $jb_mysql_link) or die (mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$_SESSION["LANG"] = strtoupper($row["lang_code"]);
// save the requested language
setcookie("SAVED_LANG", strtoupper($row["lang_code"]), 2147483647);
echo "Invalid language. Reverting to default language.";
}
} elseif (!isset($_SESSION["LANG"])) {
// get the default language, or saved language

if ($_COOKIE['SAVED_LANG']!='') {
$_SESSION["LANG"] = strtoupper($_COOKIE['SAVED_LANG']);

} else {

$sql = "SELECT * FROM lang WHERE `is_default`='Y' ";
if ($result = mysql_query ($sql, $jb_mysql_link)) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$_SESSION["LANG"] = strtoupper($row['lang_code']);
if ($row['charset']!='') {
setlocale(LC_TIME, $row['charset']);
}
} else {
$_SESSION["LANG"] = 'EN';

}
}

}

global $AVAILABLE_LANGS;
global $LANG_FILES;
global $FCK_LANG_FILES;

// load languages into array.. map the language code to the filename
// if mapping didn't work, default to english..

$sql = "SELECT * FROM lang ";
if ($result = mysql_query ($sql, $jb_mysql_link)) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$lang_code = strtoupper($row['lang_code']);
$AVAILABLE_LANGS [$lang_code] = $row['name'];
$LANG_FILES[$lang_code] = $row['lang_filename'];
$FCK_LANG_FILES[$lang_code] = $row['fckeditor_lang'];
}

if (($_SESSION["LANG"] != '') ) {
include ($LANG_FILES[$_SESSION["LANG"]]);

} else {
include ("english.php");
}

} else {
$DB_ERROR = mysql_error();

}


?>

Please help

Thank you in advance
deepdiver01's Avatar
Senior Member with 729 posts.
 
Join Date: Dec 2004
Location: Cairns, Australia
Experience: Intermediate
08-Jul-2008, 05:53 AM #2
Hi sidekick007.

My first thought is that there may be a mistake in the database data you have in the config.php file, or you are missing an element in the setup of the script.

Could you let us know which script you are trying to load and perhaps someone who has used that script before could help further.
__________________
Six mumfs ago I coodnt spel injineer. Now I are wun.

Domain Names, Web Hosting
Free Online Games | Free Flash Games
Australian Domain Names
Motor Finance Wizard Information Base
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
08-Jul-2008, 06:21 AM #3
Where do you set $jb_mysql_link?
00trav's Avatar
Computer Specs
Senior Member with 172 posts.
 
Join Date: Sep 2007
Experience: Advanced (in certain area
08-Jul-2008, 06:35 PM #4
I don't think its the $jb_mysql_link since it would give an error earlier on the page. it might be the actually if comparison. try breaking it up

instead of this:

if ($result = mysql_query ($sql, $jb_mysql_link))

use
$result = mysql_query($sql, $jb_mysql_link) or die (mysql_error());
if (mysql_num_rows($result)>0){
//rest of stuff here
}
or break it up more
$result = mysql_query($sql, $jb_mysql_link) or die (mysql_error());
$rows = mysql_num_rows($result);
if ($rows>0){
//rest of stuff
}

That way you can break it down and see what is going on.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
09-Jul-2008, 12:06 PM #5
I don't think its the $jb_mysql_link since it would give an error earlier on the page.[/quote]

Why would it give an error?

The error is that the mysql_resource link is not valid, so it probably isn't being set correctly.
00trav's Avatar
Computer Specs
Senior Member with 172 posts.
 
Join Date: Sep 2007
Experience: Advanced (in certain area
09-Jul-2008, 12:13 PM #6
The reason I don't think the mysql_resource is being set incorrectly is because if it was, then the error would occur during the first 'if' statement which incorporates a mysql_query using jb_mysql_link. and jb_mysql_link is not redefined before the next query.
Chicon's Avatar
Computer Specs
Distinguished Member with 6,673 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
09-Jul-2008, 01:57 PM #7
if ($result = mysql_query ($sql, $jb_mysql_link)) { is not correct.
It must be :
if ($result == mysql_query ($sql, $jb_mysql_link)) {

See : http://www.w3schools.com/php/php_if_else.asp
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,715 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
09-Jul-2008, 06:39 PM #8
Quote:
Originally Posted by Chicon View Post
if ($result = mysql_query ($sql, $jb_mysql_link)) { is not correct.
It must be :
if ($result == mysql_query ($sql, $jb_mysql_link)) {
Both are syntactically correct but they have different meanings.

if ($result = mysql_query ($sql, $jb_mysql_link)) {
This will assign the result of the call to mysql_query() to $result and that value will be used in the boolean evaluation of the if condition. So, if mysql_query() returns 0, the if condition will be false. If mysql_query() returns anything other than 0, the if condition will be true.

if ($result == mysql_query ($sql, $jb_mysql_link)) {
This will compare the return value of mysql_query() with the value if $result. If $result hasn't been properly initialized, the if condition won't evaluate as intended and might consistently evaluate as false.

I think 00trav is on to something.

Peace...
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
10-Jul-2008, 05:54 AM #9
Quote:
Originally Posted by 00trav View Post
The reason I don't think the mysql_resource is being set incorrectly is because if it was, then the error would occur during the first 'if' statement which incorporates a mysql_query using jb_mysql_link. and jb_mysql_link is not redefined before the next query.
If $_REQUEST['lang'] isn't set than the first query would never run.

Check the if structures.

Quote:
Originally Posted by Chicon View Post
if ($result = mysql_query ($sql, $jb_mysql_link)) { is not correct.
It must be :
if ($result == mysql_query ($sql, $jb_mysql_link)) {

See : http://www.w3schools.com/php/php_if_else.asp
Thats just a more simpler version of

if (($result = mysql_query ($sql, $jb_mysql_link)) == true)
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,715 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
10-Jul-2008, 11:00 AM #10
It's true the previous references to $jb_mysql_link are not in an if statement but his point is $jb_mysql_link was referenced before the statements identified in error and didn't generate any errors at those points in the script.

Peace...
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
10-Jul-2008, 11:12 AM #11
Quote:
Originally Posted by tomdkat View Post
It's true the previous references to $jb_mysql_link are not in an if statement but his point is $jb_mysql_link was referenced before the statements identified in error and didn't generate any errors at those points in the script.

Peace...
But that code never ran!

Here is the cleaned up code which is a lot easier to read:

PHP Code:
<?php

//if(!empty($_GET)) extract($_GET);
//if(!empty($_POST)) extract($_POST);





if (isset($_REQUEST['lang'])) { /* ### either this will run or the code in the next structure will run. if the code in the next structure was run THAN THIS WILL NEVER RUN! ### */
    
$sql "SELECT * FROM lang WHERE `lang_code`='".$_REQUEST['lang']."'";
    
$result mysql_query($sql$jb_mysql_link) or die (mysql_error());
    if (
mysql_num_rows($result)>0) {
        
$_SESSION["LANG"] = strtoupper($_REQUEST["lang"]);
        
// save the requested language
        
setcookie("SAVED_LANG"strtoupper($_REQUEST["lang"]), 2147483647);
    }
    else {
        
$sql "SELECT * FROM lang WHERE `is_default`='Y'";
        
$result mysql_query($sql$jb_mysql_link) or die (mysql_error());
        
$row mysql_fetch_array($resultMYSQL_ASSOC);
        
$_SESSION["LANG"] = strtoupper($row["lang_code"]);
        
// save the requested language
        
setcookie("SAVED_LANG"strtoupper($row["lang_code"]), 2147483647);
        echo 
"Invalid language. Reverting to default language.";
    }
}
elseif (!isset(
$_SESSION["LANG"])) {
    
// get the default language, or saved language

    
if ($_COOKIE['SAVED_LANG']!='')
        
$_SESSION["LANG"] = strtoupper($_COOKIE['SAVED_LANG']);
    else {
        
$sql "SELECT * FROM lang WHERE `is_default`='Y' ";
        if (
$result mysql_query ($sql$jb_mysql_link)) {
            
$row mysql_fetch_array($resultMYSQL_ASSOC);
            
$_SESSION["LANG"] = strtoupper($row['lang_code']);
            if (
$row['charset']!='') {
                
setlocale(LC_TIME$row['charset']);
            }
        }
        else
            
$_SESSION["LANG"] = 'EN';
    }
}



global 
$AVAILABLE_LANGS;
global 
$LANG_FILES;
global 
$FCK_LANG_FILES;

// load languages into array.. map the language code to the filename
// if mapping didn't work, default to english..

$sql "SELECT * FROM lang ";
if (
$result mysql_query ($sql$jb_mysql_link)) {
    while (
$row mysql_fetch_array($resultMYSQL_ASSOC)) {
        
$lang_code strtoupper($row['lang_code']);
        
$AVAILABLE_LANGS [$lang_code] = $row['name'];
        
$LANG_FILES[$lang_code] = $row['lang_filename'];
        
$FCK_LANG_FILES[$lang_code] = $row['fckeditor_lang'];
    }

    if (
$_SESSION["LANG"])
        include (
$LANG_FILES[$_SESSION["LANG"]]);
    else
        include (
"english.php");

}
else
    
$DB_ERROR mysql_error();
?>
See my code comment.

PHP errors are really so beautiful because they are so helpful. Just read the PHP error and it becomes obvious as to what the problem is.
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,715 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
10-Jul-2008, 11:23 AM #12
Thanks for the cleaned up version. You're right, $jb_mysql_link is never initialized in the script, anywhere. Good catch.

Peace...
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
10-Jul-2008, 11:46 AM #13
Quote:
Originally Posted by tomdkat View Post
Thanks for the cleaned up version. You're right, $jb_mysql_link is never initialized in the script, anywhere. Good catch.

Peace...
Thank you.

But really, IMO, this is a non-problem, considering how helpful PHP errors are.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:46 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.