title: mysql_real_escape_string() expects parameter 1 to be string, object given
body: <p>Hey I'm a PHP newbie setting up a "fetch, post to db, allow delete" project here and I've fetched the data, printed the DB rows and now I'm adding functionality to delete each row by <code>'$id'</code> but I'm running into this error. </p>
  
  <p>I highlighted line 81 with astricks as well as two comment blocks above and below so you can find it easily.</p>
  
  <p>Thanks for helping me learn.</p>
  
  <pre><code>&lt;?php
  
  // ***** MagicQuoteFix ***** //
  
  if (get_magic_quotes_gpc())  
  {  
    function stripslashes_deep($value)  
    {  
      $value = is_array($value) ?  
          array_map('stripslashes_deep', $value) :  
          stripslashes($value);  
      return $value;  
    }  
    $_POST = array_map('stripslashes_deep', $_POST);  
    $_GET = array_map('stripslashes_deep', $_GET);  
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);  
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);  
  } 
  
  // ***** Begin Connection Info ***** //
  
  $connection = mysqli_connect('localhost', 'ijdbuser', 'ijdbpw');
  
  if (!$connection)
  {
      $error = 'Unable to connect to the database server.';
      include 'error.html.php';
      exit();
  }
  
  if (!mysqli_set_charset($connection, 'utf8'))
  {
      $output = 'Unable to set database connection encoding.';
      include 'output.html.php';
      exit();
  }
  
  if (!mysqli_select_db($connection, 'ijdb'))
  {
      $error = 'Unable to locate the joke database.';
      include 'error.html.php';
      exit();
  }
  
  // ***** Display DB ***** //
  
  $result = mysqli_query($connection, 'SELECT id, joketext FROM joke');
  
  if (!$result)
  {
      $error = 'Error fetching jokes: ' . mysqli_error($connection);
      include 'error.html.php';
      exit();
  }
  
  while ($row = mysqli_fetch_array($result))
  {
      $jokes[] = array('id' =&gt; $row['id'], 'text' =&gt; $row['joketext']);
  }
  
  if (isset($_GET['addjoke'])) {}
  
  else
  {
      include 'jokes.html.php';
  }
  
  // 
  
  
  // ***** Begin Add/Remove DB Options ***** //
  
  if (isset($_GET['addjoke']))
  {
      include 'form.html.php';
      exit();
  }
  
  if (isset($_GET['deletejoke']))
  {
  // LINE 81 //
  ******81.****** $id = mysql_real_escape_string($connection, $_POST['id']);
  // LINE 81 //
  
      $sql = "DELETE FROM joke WHERE id='$id'";
      if (!mysqli_query($connection, $sql))
      {
          $error = 'Error deleting joke: ' . mysqli_error($connection);
          include 'error.html.php';
          exit();
      }
      //header('Location: .');
      exit();
  
  }
  
  if (isset($_POST['joketext']))
  {
      $joketext = mysql_real_escape_string($connection, $_POST['joketext']);
  
      $sql = 'INSERT INTO joke SET
          joketext="' . $_POST['joketext'] . '",
          jokedate=CURDATE()';
  
      if (!mysqli_query($connection, $sql))
      {
          $error = 'Error adding submitted joke: ' . mysqli_error($connection);
          include 'error.html.php';
          exit();
      }
      header('Location: .');
      exit();
  }
  
  
  
  
  ?&gt;
  </code></pre>