double0201 2018-03-04 15:08
浏览 54
已采纳

因某些原因无法传递变量? PHP

Some reason when i call $_POST['xalue'] it will only return the first index of $xaxis.

$xaxis = '["-100","-100","240","1056","3560","-650","5980.5","1020"]'

im just trying to pass the information so when the button is pressed to add the dashboard i can pass the data along. Thank you

$query = mysqli_query($db, "SELECT ID From users WHERE Username='$user'");
$fetch = mysqli_fetch_assoc($query);
$data = $fetch{"ID"};

$sql = "SELECT dashboardname FROM dashboards WHERE dashboarduserID=$data";
$result = $db->query($sql);
$addarray = array();
if ($result->num_rows > 0) {
    global $xaxis;
    echo $xaxis;
    while ($row = $result->fetch_assoc()) {
        array_push($addarray, $row['dashboardname']);
    }
    echo '<form method="post">';?>
    <input type="text" name="xvalue" value="<?php echo $xaxis ?>">
    <?php
    echo 'Add current graph to :';
    echo '<select name="addgraph">';
    foreach ($addarray as $item) {
        echo '<option value="' . $item . '">' . $item . '</option>';
    }
    echo '</select>';
    echo '<input type="submit" name="addtodash" value="Add">';
    echo '</form>';
} else {
    echo "0 results";
    if (isset($_REQUEST["addtodash"])) {
    $xaxis = $_POST['xvalue'];
    $query = mysqli_query($db, "SELECT ID From users WHERE Username='$user'");
    $fetch = mysqli_fetch_assoc($query);
    $data = $fetch{"ID"};
    $nameofdash = $_POST['addgraph'];
    mysqli_query($db, "INSERT INTO dashboardsdata (userid,dashboardname,xdata,ydata) VALUES ($data,\"$nameofdash\",\"$xaxis\",\"$yaxis\");");
    echo "done";
}
  • 写回答

2条回答 默认 最新

  • dongwuwu6104 2018-03-04 15:15
    关注

    The double quotes in $xvalue will match the double quotes that are used to delimit the value="..." attribute. You need to encode them:

    <input type="text" name="xvalue" value="<?php echo htmlspecialchars($xaxis); ?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝