Php 尝试将数组值用作SQL插入值
嘿,伙计们,我正在尝试在一个新的查询中使用我从上一个查询中获得的值,该值是存储在数组中的字符串,它们是$Name和$Email变量,当我将它们转储时看起来是这样的。。。字符串“nathgold”(长度=8)。。。。我想在插入新查询时使用该值。我收到错误注意:第30行的C:\wamp\www\login\post.php中的数组到字符串转换Php 尝试将数组值用作SQL插入值,php,mysql,sql,arrays,string,Php,Mysql,Sql,Arrays,String,嘿,伙计们,我正在尝试在一个新的查询中使用我从上一个查询中获得的值,该值是存储在数组中的字符串,它们是$Name和$Email变量,当我将它们转储时看起来是这样的。。。字符串“nathgold”(长度=8)。。。。我想在插入新查询时使用该值。我收到错误注意:第30行的C:\wamp\www\login\post.php中的数组到字符串转换 <?php include_once('connect-db.php'); session_start(); if(!isset($_SESSION[
<?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);
您的语法有错误<代码>$Name=$userRow=['username']
应该是$Name=$userRow['username']
对于$Email…
您现在所做的基本上是将$userRow设置为一个包含单词“username”的数组,然后将$Name设置为该数组。