从主页发送到帖子页面的Value显示为单词* Array *

时间:2018-06-25 11:22:08

标签: php html

嗯,很容易解释

Objectif :我想将从sql(可由用户添加)中获取的ID值发送到“帖子页”表单

当前错误:我尝试了这段代码

第一页

    <?php
 session_start();

 $conn = mysqli_connect("localhost", "localhost", "localhost", "localhost");
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$buyer      = $_SESSION['username'];
$sql_shells = "SELECT buytime,id,situation,buyer FROM shells WHERE situation = 'sold' AND buyer = '$buyer'  ";
$dt = new DateTime();
$dt->modify('+172799 seconds');
$hi = $dt->format('Y-m-d H:i:s');
$_SESSION["sup"] = [];

$result = $conn->query($sql_shells);
if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {
$_SESSION["sup"][] = $row['id'];
$_SESSION["sup"] = implode(',', $session['sup']);  // use this var

if ($hi <  $row['buytime']) {

         }else{

  echo " <form action='action.php' method='get'>
  Thanks for buying from our shop , if the item with id <input type='submit' value='" . $row['id'] ."' class='btn-link'/>  </form>";

  echo "<form action='action1.php' method='post'>
  is a bad tool , you can report by clicking on the following button <input  type='submit' value='Report Item' />
       </form>";
  }
  }
  }else {

  }

 ?>

及其动作的表单页面

<?php
session_start();
if (isset($_SESSION['username'])) {

server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "localhost", "localhost", 
"localhost");

if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$trn_date = date("Y-m-d H:i:s");

$seller = $_SESSION['username']; 
$id = $_POST['whatever'];
$id = explode(',', $id); // You now have an array of IDs.
$sql = "INSERT INTO reports (reporter,stats,trn_date,itemid) VALUES 
('$seller','Opened','$trn_date','$id')";
if(mysqli_query($link, $sql)){
echo $id;
echo $seller;
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

 } else
  {
  header("location:/quickshops/login.php");
 }
?>

插入的值是:数组从字面上看是数组而不是id,其他都可以

顺便说一句:已经测试过,当我在第一页中回显它们时,它们看起来很好,就像id是实数

1 个答案:

答案 0 :(得分:0)

您似乎正在执行以下操作(解释);

$id = explode(...);
/* other code */
echo $id;

如评论中所述,这将打印 Array ,因为这是爆炸返回的类型。
如果您的数据是;

$_POST['whatever'] = "a,b,c,d"

将其分解为id将会产生;

$id = array(
    a
    b
    c
    d
)

因此,您需要循环这些结果以使用它们,或通过关联调用(分别如下所示)

foreach ($id as $an_id)
{
    echo "ID = {$an_id} <br />";
}

echo "ID = {$id[0]} <br />";
echo "ID = {$id[1]} <br />";
echo "ID = {$id[2]} <br />";
echo "ID = {$id[3]} <br />";

这两个都将打印;

ID = a
ID = b
ID = c
ID = d

鉴于此,下面将给出 Array 作为输出;

print "{$id} <br />";

如果要将其重新设置为1个字符串,则可以执行以下操作以将其恢复为正常状态; <​​/ p>

print implode(",", $id);

为您提供以下输出;

a,b,c,d