sam
sam

Reputation: 1

Warning: mysql_fetch_array() expects parameter 1 to be resource sql

I'm having some trouble about inserting a new post in my database. I ran it on shared host and there was no problem, but on my vps it gives me the following error:

 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/sam/public_html/admin/include/functions.php on line 37

 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/sam/public_html/admin/include/functions.php on line 46

 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/sam/public_html/admin/include/functions.php on line 55

Here is my code (functions.php) :

<?php
include("../../Connections/confing.php");

function offset_time($time,$ofset)
{
$time_array = explode(":",$time);
$am = "";

$hours   = $time_array[0];
$minutes = $time_array[1];

$new_hour = $hours +10;


if($new_hour>24){
$new_hour = $new_hour - 24;
$am = "am";
}else{
$am = "pm";
}

if ($new_hour>12){
$new_hour = $new_hour -12;
}


$offset_time = $new_hour . ":". $minutes ." ".$am ;

return $offset_time;
}

//---------------------- Get Cat ID -------------------------------------------
function getcatid($newsid){

$minSql  = "select catid from art_news where newsid=".$newsid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);  
$catid   = $RSget["catid"];
return $catid;  
}

function getzoneid($newsid){

$minSql  = "select zoneid from art_news where newsid=".$newsid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);
$zoneid  = $RSget["zoneid"];
return $zoneid; 
}

function get_news_lang($newsid){

$minSql  = "select lang from art_news where newsid=".$newsid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);
$lang  = $RSget["lang"];
return $lang;   
}

function get_art_lang($artid){

$minSql  = "select lang from art_articles where artid=".$artid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);
$lang  = $RSget["lang"];
return $lang;   
}

function get_video_lang($albumid){

$minSql  = "select lang from video_albums where albumid=".$albumid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);
$lang  = $RSget["lang"];
return $lang;   
}

function get_gallery_lang($albumid){

$minSql  = "select lang from glr_albums where albumid=".$albumid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);
$lang  = $RSget["lang"];
return $lang;   
}


function getphoto_newsid($photoid){

$minSql  = "select newsid from art_photos where photoid=".$photoid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);
$newsid  = $RSget["newsid"];
return $newsid; 
}


function get_photo_albumid($photoid){

$minSql  = "select albumid from glr_photos where photoid=".$photoid;
$RSofGet = mysql_query($minSql);
$RSget   = mysql_fetch_array($RSofGet);
$albumid = $RSget["albumid"];
return $albumid;    
}
?>

Upvotes: 0

Views: 88

Answers (2)

sam
sam

Reputation: 1

when i edit it like this function getcatid($newsid){

$minSql  = "select catid from art_news where newsid=".$newsid;
if ($minSql === false) // Check if query return an error
die("minSql error: " . mysql_error());
$RSofGet = mysql_query($minSql);
if ($RSofGet === false) // Check if query return an error
die("RSofGet error: " . mysql_error());
$RSget   = mysql_fetch_array($RSofGet);  
if ($RSget === false) // Check if query return an error
die("RSget error: " . mysql_error());
$catid   = $RSget["catid"];
return $catid;  
}   

i get this error : RSofGet error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Upvotes: 0

Dario
Dario

Reputation: 4035

You should provide a valid sql results resource as first parameter (mysql_query return FALSE in case of error):

<?php
mysql_connect("localhost", "user", "password") or
    die("Connect error: " . mysql_error());
mysql_select_db("mydb");

$sqlResource = mysql_query("SELECT id, name FROM mytable");

if ($sqlResource === false) // Check if query return an error
    die("Query error: " . mysql_error());

while ($row = mysql_fetch_array($sqlResource, MYSQL_NUM)) {
    printf("ID: %s  Name: %s", $row[0], $row[1]);  
}

mysql_free_result($sqlResource);
?>

PS: mysql* functions ares deprecated, use mysqli or better PDO extensions.

Upvotes: 1

Related Questions