douyun1860 2014-04-10 15:28
浏览 102

如何从数据库中调用`id`?

i have created a form to update name into database, i have created two tables first_name and last_name into database, have look once here is my code:

$sql="
CREATE TABLE admin
(
id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(100),
last_name VARCHAR(100),
)";

Now i have created to update form here:

<div class="box">
    <h1 style="font-family: consolas">Change your name</h1><hr>
    <div id="change_name">
        <label><strong>Your current name: </strong></label>
        <?php
        include('change_setting_db.php');

        while($row = mysqli_fetch_array($result))
        {
            echo $row['first_name']." ".$row['last_name'];
        }
        ?><br><br>

        <form method="post" action="do_update_name.php">
        <label><strong>First name: </strong></label>
        <input type="text" name="first_name">
        <label><strong>Last name: </strong></label>
        <input type="text" name="last_name">
            <input type="submit" value="Submit">
        </form>

    </div>

</div>

and here is my do_update_name.php file:

<?php
$firstname=$_POST['first_name'];
$lastname=$_POST['last_name'];
$id=$_GET['id'];

$con=mysqli_connect("localhost","root","Bhawanku", "members");
// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$update =mysqli_query($con,"UPDATE admin SET first_name='$firstname' AND  last_name='$lastname' WHERE id='$id' ");
if($update){
    echo "Successfully created!!";
}
?>

Now problem is when i put new name and do submit, it shows an error:

Notice: Undefined index: id in C:\Users\Raj\PhpstormProjects\...
ew do_update_name.php on line 4
Successfully created!!
  • 写回答

2条回答 默认 最新

  • dousuo8400 2014-04-10 15:31
    关注
    <form method="post" action="do_update_name.php">
            <label><strong>First name: </strong></label>
            <input type="text" name="first_name">
            <label><strong>Last name: </strong></label>
            <input type="text" name="last_name">
                <input type="submit" value="Submit">
            </form>
    

    You have to add the ID here, so the other side can pick up the $_GET parameter ['id'] For example:

    <form method="post" action="do_update_name.php?id=1">
            <label><strong>First name: </strong></label>
            <input type="text" name="first_name">
            <label><strong>Last name: </strong></label>
            <input type="text" name="last_name">
                <input type="submit" value="Submit">
            </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入