PHP数组将字符串多重提交表单

时间:2019-01-02 12:25:56

标签: php arrays string forms

  public function query($sql, $parameters = [])
{
$query = $this->pdo->prepare($sql);
$query->execute($parameters);
var_dump($parameters);
return $query;
 }

public function delete ($id){

$parameters = [':id' => $id];

$this->query('DELETE FROM ' . $this->table . ' WHERE ' . $this- 
>primaryKey . ' = :id', $parameters);

}

<?php
$query = $products->findAll();

if(isset($_POST['delete']))
{
  if (isset($_POST['id']))
 {
    $products->delete([
  ':id' => $_POST['id'],
]);
 }
  else
  {
echo "You did not choose a id.";
 }
}
 ?>

 <form action="" method="POST">
<?php
 foreach($query as $row){
 echo "<label for='product_id'>" . $row['p_name'] . " </label> <input type='checkbox' name='id[]' value = '" . $row['product_id'] . "'>";
}
  ?>
 <input type="submit" name="delete" value="delete">

 </form>

当我提交此表单时,我得到了Array到字符串转换的错误。 我怀疑它与表单的“名称”有关,尽管我不知道为什么并且有些困惑。

1 个答案:

答案 0 :(得分:0)

在输入的名称参数末尾指定import tensorflow as tf sess = tf.Session() # First let's load meta graph and restore weights saver = tf.train.import_meta_graph('./ckpnt/my_test_model-1000.meta') saver.restore(sess, tf.train.latest_checkpoint('./ckpnt')) # Now, let's access and create placeholders variables and # create feed-dict to feed new data graph = tf.get_default_graph() w1 = graph.get_tensor_by_name("w1:0") w2 = graph.get_tensor_by_name("w2:0") feed_dict = {w1: 13.0, w2: 17.0} # Now, access the op that you want to run. op_to_restore = graph.get_tensor_by_name("op_to_restore:0") print (sess.run(op_to_restore, feed_dict)) # This will print 60 which is calculated # using new values of w1 and w2 and saved value of b1. 将指示浏览器将每个输入作为数组的元素而不是单个字符串发送。

[]

您可以使用<input type='checkbox' name='id[]' > 查看数组中的内容。如果只需要一个字符串,则删除var_dump($_POST['id'])。否则,您将需要遍历每个值并对其进行处理。