0

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;    
}
?>
2
  • what is the error on $RSget = mysql_fetch_array($RSofGet); Commented Jun 11, 2016 at 9:00
  • Avoid usage of the mysql syntax as it has been deprecated and replaced with mysqli. Use either mysqli or PDO. If you would like a tool to help upgrade try this: php-shift.com/upgrade-mysql-mysqli Commented Jun 11, 2016 at 9:04

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

i use it like this $Db_Host="localhost"; $Db_User="aqabacc_sam"; $Db_Pass="sam@123"; $Db_Name="aqabacc_sam"; $con = mysql_connect($Db_Host,$Db_User,$Db_Pass); if (!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db($Db_Name, $con);
Yes, in the same way you should to check if mysql_query return false. @sam
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); $RSget = mysql_fetch_array($RSofGet); $catid = $RSget["catid"]; return $catid; }
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.