-2

in a wordpress site, this code gives the following error I tried to change it to mysqli, but the same error anybody has an idea where is the problem, how to deal with. I searched a lot of answers here but non worked for me.

this code is part of file "class_design.php"

function MYORDERS($user_id){

global $wpdb,$PPT, $ThemeDesign, $userdata;
get_currentuserinfo(); 
$content=""; 
$dwl_content=""; 
$td=1; 
$STRING ='<input type="hidden" value="" id="moreinfodiv" name="moreinfodiv">';
$date_format = get_option('date_format') . ' ' . get_option('time_format');
if(!is_numeric($user_id)){ die("nice try!"); }


$SQL = "SELECT * FROM 
       ".$wpdb->prefix."orderdata
       WHERE cus_id='".$userdata->ID."'
       GROUP BY order_id
       ORDER BY autoid DESC";  

$posts = mysql_query($SQL, $wpdb->dbh) or die(mysql_error().' on line: '.__LINE__);

  if ($posts && mysql_num_rows($posts) > 0) {

    while ($thepost = mysql_fetch_object($posts)) { if($thepost->order_total > 0){

    if($thepost->order_status ==0){  
    $status = $PPT->_e(array('myaccount','_paymentstatus0'));
    }elseif($thepost->order_status ==3){ 
    $status = "<b style='color:green;'>".$PPT->_e(array('myaccount','_paymentstatus1'))."</b>";
    }elseif($thepost->order_status ==5){ 
    $status = "<b style='color:green;'>".$PPT->_e(array('myaccount','_paymentstatus2'))."</b>";
    }elseif($thepost->order_status ==6){  
    $status = "<b style='color:red;'>".$PPT->_e(array('myaccount','_paymentstatus3'))."</b>";
    }elseif($thepost->order_status ==7){ 
    $status = "<b style='color:blue;'>".$PPT->_e(array('myaccount','_paymentstatus4'))."</b>";
    }elseif($thepost->order_status ==8){ 
    $status = "<b>".$PPT->_e(array('myaccount','_paymentstatus5'))."</b>";
    }  

error appears in the page

Meenesh Jain
  • 2,532
  • 2
  • 19
  • 29
agm
  • 19
  • 6
  • I was going to flag this as a duplicate but there are so many questions like this I couldn't decide which one... so I'll just plop the obligatory **stop using the deprecated `mysql_` extension** notice instead : http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – CD001 Jul 02 '15 at 13:43
  • I appreciate that for you :) – agm Jul 02 '15 at 13:48

1 Answers1

2

You are passing a $wpdb object to mysql_query which expects a resource, meaning a mysql connection.

Try to use the $wpdb object directly like so:

$SQL = "SELECT * FROM 
       ".$wpdb->prefix."orderdata
       WHERE cus_id='".$userdata->ID."' 
       GROUP BY order_id 
       ORDER BY autoid DESC";
$results = $wpdb->get_results($SQL);

foreach ($posts as $post) {

    // do your business here

}
Meenesh Jain
  • 2,532
  • 2
  • 19
  • 29
Alex Andrei
  • 7,315
  • 3
  • 28
  • 42