douyu7879 2016-02-27 02:50
浏览 9
已采纳

PHP MySQLi没有更新

I have been trying to make a form where I can update two fields one field is going be admin_welcomebox and admin_author and I'm trying update it by the id so here go my code

<div class="col-lg-6">                      
    <div class="panel panel-color panel-inverse">                               
        <div class="panel-heading">
            <h3 class="panel-title">Welcome Box Update</h3>
        </div>

        <?php
            if(isset($_POST["submit"])){
                $servername = "localhost";
                $username = "trres";
                $password = "sss";
                $dbname = "txxxs";

                // Create connection
                $conn = new mysqli($servername, $username, $password, $dbname);
                // Check connection
                if ($conn->connect_error) {
                    die("Connection failed: " . $conn->connect_error);
                }

                $sql = "UPDATE admin_news SET welcomebox = '{$admin_news}' SET author = {$admin_author} id='{$id}'";

                if ($conn->query($sql) === TRUE) {
                    echo "<h4 class='bg-success'>You have updated admin welcome box.</h4>";
                } else {
                    echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
                }
                $conn->close();
            }
        ?>
        <div class="panel-body">
            <form method="post" action="">
                <div class="form-group">
                    <label for="welcomebox">Welcome Box</label>
                    <textarea type="text" name="welcomebox" id="welcomebox" placeholder="Enter Your Message" class="form-control"></textarea>
                </div>      
                <div class="form-group">
                    <label for="author">Author Name</label>
                    <input type="text" name="author" id="author" placeholder="Author Name" class="form-control" / >
                </div>                                          
                <div class="form-group text-right m-b-0">
                    <button class="btn btn-primary waves-effect waves-light" type="submit" name="submit" id="submit">
                        Update Info
                    </button>
                </div>
            </form>                                 
        </div>                                              
    </div>                              
</div>

When I try update it just refresh the page nothing else.

  • 写回答

2条回答 默认 最新

  • dongluo8439 2016-02-27 05:31
    关注

    You didn't define $admin_news ,$admin_author and $id as well. define first.

    Try this code :-

    <div class="col-lg-6">                      
    <div class="panel panel-color panel-inverse">                               
        <div class="panel-heading">
            <h3 class="panel-title">Welcome Box Update</h3>
        </div>
    
        <?php
            if(isset($_POST["submit"])){
                $servername = "localhost";
                $username = "trres";
                $password = "sss";
                $dbname = "txxxs";
    
                // Create connection
                $conn = new mysqli($servername, $username, $password, $dbname);
                // Check connection
                if ($conn->connect_error) {
                    die("Connection failed: " . $conn->connect_error);
                }
                $id=$_POST['id'];
                $admin_news=$_POST['welcomebox']; 
                $admin_author=$_POST['author']; 
    
                $sql = "UPDATE admin_news SET welcomebox = '$admin_news', author = $admin_author where id=$id";
    
                if ($conn->query($sql) === TRUE) {
                    echo "<h4 class='bg-success'>You have updated admin welcome box.</h4>";
                } else {
                    echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
                }
                $conn->close();
            }
        ?>
    
    
        <div class="panel-body">
                <form method="post" action="">
      <input type="hidden" name="id" value="<?php echo $id; ?>" /> <!-- put here your id  --> 
                   <div class="form-group">
                        <label for="welcomebox">Welcome Box</label>
                        <textarea type="text" name="welcomebox" id="welcomebox"                       placeholder="Enter Your Message" class="form-control"></textarea>
                    </div>      
                    <div class="form-group">
                        <label for="author">Author Name</label>
                        <input type="text" name="author" id="author" placeholder="Author Name" class="form-control" / >
                    </div>                                          
                    <div class="form-group text-right m-b-0">
                        <button class="btn btn-primary waves-effect waves-light" type="submit" name="submit" id="submit">
                            Update Info
                        </button>
                    </div>
                </form>                                 
            </div>                                              
        </div>                              
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制