简体   繁体   English

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

[英]Trying to use an array value as an SQL insert value

Hey guys I am trying to use a value that i got from a previous query in a new one, the value is a string stored in an array, they are the $Name and $Email variables, it looks like this when i var_dump them... string 'nathgold' (length=8) .... I want to use that nathgold as a value in the insert of a new query. 大家好,我试图在新查询中使用从先前查询中获得的值,该值是存储在数组中的字符串,它们是$ Name和$ Email变量,当我var_dump它们时,它看起来像这样。 ..字符串'nathgold'(length = 8)....我想将该nathgold用作新查询插入中的值。 I get the error Notice: Array to string conversion in C:\\wamp\\www\\login\\post.php on line 30 我收到错误通知:第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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM