简体   繁体   English

我正在为更新功能开发php页面

[英]I am developing php page for update function

when page is loaded it display error that id , name and address is undefined. 加载页面时,它会显示错误消息: idnameaddress未定义。 These variable are getting on condition of edit, but i dont understand how to place these values in text filed 'value' for edit as this is not working. 这些变量处于编辑状态,但是我不明白如何将这些值放在文本“值”中进行编辑,因为这不起作用。 The main code is like this.*** also the code of update is not updating values but it displays your record is updated 主要代码是这样的。***更新代码也不是更新值,而是显示您的记录已更新

    <?php
    include 'server.php';

    if (isset($_GET['edit'])) {
        $id = $_GET['edit'];
        $update = true;
        $record = mysqli_query($con, "SELECT * FROM info WHERE id=$id");

        if (count($record) == 1) {
            $n = mysqli_fetch_array($record);
            $name = $n['name'];
            $address = $n['address'];
        }
    }
    ?>
    <!-- Form -->
    <!DOCTYPE html>
    <html>
        <head>
            <title>CReate, Update</title>
            <link rel="stylesheet" type="text/css" href="style.css">

        </head>
        <body>

            <form method="post" action="php_code.php" >
                <input type="hidden" name="id" value="<?php echo $id; ?>">
                <input type="text" name="name" value="<?php echo $name; ?>">
                <input type="text" name="address" value="<?php echo $address; ?>">

                <div class="input-group">
                    <?php if ($update == true): ?>
                        <button class="btn" type="submit" name="update" >Update</button>
                    <?php else: ?>
                        <button class="btn" type="submit" name="submit" >save</button>
                    <?php endif ?>
                </div>
            </form>
            <!-- Display -->

            <?php
            $i = 1;
            $q = mysqli_query($con, "select*from info");
            while ($f = mysqli_fetch_array($q)) {
                ?>
                <table>
                    <th> sr N0</th>
                    <th> Name</th>
                    <th> address</th>
                    <th> Action</th>
                    <tr>
                        <td>   <?php echo $i; ?>  </td>
                        <td>   <?php echo $f['name']; ?>  </td>
                        <td>   <?php echo $f['address']; ?>  </td>
                        <td><a href="index.php?edit=<?php echo $f['id']; ?>" class="edit_btn" >Edit</a></td>
                    </tr>
                    <?php $i ++;
                }
                ?>
            </table>
        </body>
    </html>



<?php
include 'server.php';
if (isset($_POST['save']))
{
    $name= $_POST['name'];
    $add= $_POST['address'];
    $q = "INSERT into info (name,address) VALUES ('$name', '$add')";
    mysqli_query($con, $q);
    echo "inserted";
}

 if (isset($_POST['update']))
 {
    $uname= $_POST['name'];
    $uaddress= $_POST['address'];
    $q = "UPDATE info set name= '$uname', adress= '$uaddress' WHERE id = $id";
    mysqli_query($con, $q);
    echo "updated";

 }


?>

Make 使

if (count($record) == 1 ) {

to

if (mysqli_num_rows($record) == 1 ) {

暂无
暂无

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

相关问题 我正在使用php和mysql.my开发网站,每个页面文件扩展名都以.php扩展名结尾如何避免这种情况? - I am developing website using php and mysql.my each page file extension end with .php extension how do i avoid that? PHP函数在发布时不起作用,但是如果我在页面上则可以工作 - PHP function not working on post but works if I am on the page 我正在开发一个用于求职的android应用程序。在这里我正在使用PHP作为后端 - I am developing an android app for job search .here i am using PHP as back end 我无法使用php和angularjs使用更新功能将记录更新到数据库中 - i am not able to update the record using update function into the database using php and angularjs 我正在使用 $_SESSION('ID'),通过 php 页面更新表不起作用并且没有错误 - I am Using $_SESSION('ID') , To UPDATE into table not working and no error through php page 我在laravel中开发注册表,但是单击“提交”按钮时,它不会重定向到我的登录页面,这是为什么? - i am developing a registration form in laravel but when the submit button is clicked it wont redirect to my login page why is that? 如何在开发 octobercms 网站时解决此作曲家错误,我使用的是 php 7.4 - how to solve this composer error when developing octobercms website ,i am using php 7.4 我在orangehrm中开发新模块 - I am developing new module in orangehrm 我正在使用 HTML 和 PHP 编写登录页面 - I am coding a login page with HTML and PHP 如何知道我在哪个php页面上? - How to know which php page I am on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM