Warning: mysql_query():supplied argument is not a valid MySQL-Link resource

Discussion in 'PHP' started by sidekick, Jul 7, 2008.

  1. #1
    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 :confused:

    Thank you in advance
     
    sidekick, Jul 7, 2008 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    $jb_mysql_link is the culprit, it was probably obtained when establishing connection such as:

    $jb_mysql_link = mysql_connnect(.............);

    or

    $jb_mysql_link = mysql_pconnnect(.............);

    That actually means the connection is not properly established with mysql engine. Check your connection establishing code.

    regards
     
    Vooler, Jul 7, 2008 IP
  3. SecureWebDev

    SecureWebDev Active Member

    Messages:
    677
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    80
    #3
    by the way, sanatize your input using mysql_real_escape_string(); function in order to prevent SQL injections against your website.
     
    SecureWebDev, Jul 7, 2008 IP