dongzhuifeng1843 2013-05-21 10:51
浏览 19
已采纳

帖子没有完全发布PHP

I have a select value 'post', when someone wants to change the status of the post from unsolved to solved they have to choose a post en than click 'change to solved'

The problem is when I click on the button, it doesn't change because PHP takes not the whole title of the post. So when my post is called 'Photoshop crashes', it only sends 'Photoshop'. That's why it doesn't update in my database, the query can't find the right post, when the title of the post is only 1 word, my table gets updated.

<?php
if (isset($_POST['btnSolved'])) 
{
// wanneer er op de knop geklikt is proberen we user te saven in de databank
if (!empty($_POST['btnSolved'])) 
{
    $solved = $_POST['unsolved'];
    $conn = new mysqli("localhost","root","root","PhpProject");
    if ($conn -> connect_errno) {
        throw new Exception("No connection with database!");

    } else {
        $sql = "UPDATE Posts SET status = 'Solved' WHERE post='".$solved."'";
    }
   }
    $conn->query($sql);
  }
  ?>

In my body:

<h3>Change status</h3>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
            <?php
            if(mysqli_num_rows($showBugs) > 0)
            {
                echo "<select name= unsolved>"; 
                while ($row = mysqli_fetch_assoc($showBugs)) 
                {
                    echo "<option value=" . $row['subject'] . ">" . $row['subject'] . "</option>";
                }
                echo "</select>";
            }
            ?>
            <br />
            <input class="btn btn-info dropdown-toggle" type="submit" name="btnSolved" value="Change to solved" />
        </form>

This is what I get when I do a print of the $sql

UPDATE Posts SET status = 'Solved' WHERE post='Photoshop'

Does someone know why PHP can post 1 word, but not the whole title? It might be something stupid, but I don't know how to fix this.

  • 写回答

4条回答 默认 最新

  • douhuan6065 2013-05-21 10:57
    关注

    Try enclosing the value in single quotes,

    echo "<option value='" . $row['subject'] . "'>" . $row['subject'] . "</option>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c