gpt4 book ai didi

php - 尝试使用数组值作为 SQL 插入值

转载 作者:行者123 更新时间:2023-11-29 21:22:04 24 4
gpt4 key购买 nike

嘿伙计们,我正在尝试在新查询中使用从上一个查询中获得的值,该值是存储在数组中的字符串,它们是 $Name 和 $Email 变量,当我var_dump 他们... string 'nathgold' (length=8) .... 我想使用该 nathgold 作为新查询插入中的值。我收到错误 注意:第 30 行 C:\wamp\www\login\post.php 中的数组到字符串转换

<?php
include_once('connect-db.php');
session_start();

if(!isset($_SESSION['isLogged']))
{
header("Location: home.php");
die();
}

if (!isset($_REQUEST['MBID'])) exit;
if (!isset($_REQUEST['Parent'])) {
$Parent = 0;
} else {
$Parent = $_REQUEST['Parent'];
}

if (isset($_POST['Title'])) {

$user_info=mysqli_query($connection, "SELECT * FROM usertest WHERE id=".$_SESSION['user']);
$userRow=mysqli_fetch_array($user_info);

$Name = $userRow=['username'];
$Email = $userRow=['email'];
$Title = mysqli_real_escape_string($connection, $_POST['Title']);
$Message = mysqli_real_escape_string($connection, $_POST['Message']);
$CurrentTime = time();
// other filtering here...

$result = mysqli_query($connection, "INSERT INTO mbmsgs (MBID, Parent, Poster, Email, Title, Message, DateSubmitted) VALUES ({$_REQUEST['MBID']}, $Parent, ".$Name.", ".$Email.", '$Title', '$Message', $CurrentTime);");
if ($result) {
echo "Your message has been posted - thanks!<br /><br />";
echo "<A HREF=\"mbindex.php?MBID={$_REQUEST['MBID']}\">Back to messageboard</a>";
exit;
} else {
echo "There was a problem with your post - please try again.<br /><br />";
}
}
?>
<form method="post" action="post.php">

Message title: <input type"text" name="Title" /><br /><br />
Message:<BR />
<textarea name="Message" rows="10" cols="40"></textarea><br /><br />
<input type="hidden" name="MBID" value="<?php echo $_REQUEST['MBID']; ?>" />
<input type="hidden" name="Parent" value="<?php echo $Parent; ?>" />
<input type="submit" value="Post" />
</form>

最佳答案

将 $name 转换为字符串:

use implode("|",$name);

关于php - 尝试使用数组值作为 SQL 插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35676697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com