0

I'm looking for an explanation / fix for this error. I'm using the following script. This is my first time using multi_query :

        $storyidr=$_POST['storyidr'];
$mysqli = mysqli_connect($dbhost,$dbusername,$dbpasswd,$database_name) or die ("Couldn't connect to server.");
 if (mysqli_connect_errno($mysqli))
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
$sql  = "INSERT INTO ratings (storyidr, rank, entry_date) VALUES ('$_POST[storyidr]','$_POST[value]',now());"; 
$sql .= "SELECT AVG(rank) AS avrank from ratings WHERE storyidr = $storyidr";
if($mysqli->multi_query($sql))
{   
if ($result = $mysqli->store_result())
{ 
$data = mysqli_fetch_assoc($result);
$avrank = $data['avrank'];
        if(!$result)
        {
              $arr = array ('status'=>'fail');
              echo json_encode($arr);
        }
        else
        {

                echo json_encode($avrank);
        }
                exit;
}
}
rhill45
  • 559
  • 10
  • 35

1 Answers1

2

The variable $mysqli is not defined, you are assigning it to $con, Change from

$con = mysqli_connect($dbhost,$dbusername,$dbpasswd,$database_name) or die ("Couldn't connect to server.");

to

$mysqli = mysqli_connect($dbhost,$dbusername,$dbpasswd,$database_name) or die ("Couldn't connect to server.");
Nouphal.M
  • 6,304
  • 1
  • 17
  • 28
  • 1
    Also, `if (mysqli_connect_errno($con))` to `if (mysqli_connect_errno($mysqli))` – Funk Forty Niner Mar 31 '14 at 16:06
  • That did rid error, thank you! Script not working though. You wouldn't happen to notice any other problems here? I'm editing ? to post current code. When use triggers aJax, an empty value displays (no data) – rhill45 Mar 31 '14 at 16:13