title: Inserting multiple values into a database, php , sql
body: <p>Im having a problem trying to insert multiple values at the same time into the same column in a table, </p>
  
  <p>This code shows a table:
  Table Ex:</p>
  
  <pre><code>-----------------------------
  Name   | Last Name | Points |
  -----------------------------
  Test   | 185       |        |
  -----------------------------
  Test1  | 185       |        |
  -----------------------------
  Test2  | 185       |        |
  -----------------------------
  </code></pre>
  
  <p>The useradmin ca insert points for each user, but when I click summint to insert all of those values into the database I gt a message(error) 
   PDO::prepare() expects parameter 1 to be string, array given in
  and another one
  Fatal error: Call to a member function execute() on a non-objec</p>
  
  <p>Any ideas why or how to fixed?</p>
  
  <pre><code>&lt;?php
  require("coneccion.php"); 
  
  if(!empty($_POST))
  { 
  
    $query = "INSERT INTO points (sid, ais, spoints) values (1, 2, :spoints)";
    $query = array(':spoints' =&gt; $_POST['spoints']);
  
    try
    {
      $stmt = $db-&gt;prepare($query);
      $stmt = $stmt-&gt;execute($query_params);
    }
    catch(PDOException $ex)
    {
      die("Error 1 " . $ex-&gt;getMessage());
    }
    $cid = $_SESSION['cid'];
    header("Location: index.php?id=$cid");
    die("Rendirecting to index.php?id=$cid");
  }
  else
  {
  
    $id = $_SESSION['cid'];
    echo 'Course id: ' .$id ;
    $sid = $_GET['id'];
  
    $query = "SELECT DISTINCT s.studentid, s.fname, s.lname, a.assignmentpoints, s.courseid, a.courseid, a.duedate FROM students as s, assignments as a WHERE s.courseid = '$id' and s.courseid = a.courseid and a.assignmentid = '$sid' ";
    try
    {
      $stmt = $db-&gt;prepare($query);
      $stmt-&gt;execute();
    }
    catch(PDOException $ex)
    {
      die("Error 2" . $ex-&gt;getMessage());
    }
    $rowstudents = $stmt-&gt;fetchAll();
  }
  ?&gt;
  
  
  &lt;form action="index.php" method="post"&gt;
  &lt;table border=1&gt;
    &lt;tr&gt;
      &lt;th&gt;Id&lt;/th&gt;
      &lt;th&gt;First Name&lt;/th&gt;
      &lt;th&gt;Last Name&lt;/th&gt;
      &lt;th&gt;Assignment Points&lt;/th&gt; 
      &lt;th&gt;Student Points&lt;/th&gt;
    &lt;/tr&gt;
  &lt;?php foreach($rowstudents as $row): ?&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;?php echo '' . htmlentities($row['studentid'], ENT_QUOTES, 'UTF-8') . '';?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo '' . htmlentities($row['fname'], ENT_QUOTES, 'UTF-8') . '';?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo '' . htmlentities($row['lname'], ENT_QUOTES, 'UTF-8') . '';?&gt;&lt;/th&gt;
      &lt;th&gt;&lt;?php echo '' . htmlentities($row['assignmentpoints'], ENT_QUOTES, 'UTF-8') . '';?&gt;&lt;/th&gt; 
      &lt;th&gt;&lt;input type="text" name="spoints" value=""&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;?php endforeach; ?&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>