gpt4 book ai didi

php - PHP 中的 CRUD 操作...在 edit.php 中出现错误

转载 作者:行者123 更新时间:2023-11-30 23:44:37 25 4
gpt4 key购买 nike

我正在尝试使用 phpmyadmin 执行 CRUD 操作
然后当我选择编辑选项时出现错误,我尝试但没有得到它

我在编辑操作时遇到以下错误

Notice: Undefined index: edit in C:\wamp\www\projects\edit.php on line 3

( ! ) Notice: Undefined variable: id in C:\wamp\www\projects\edit.php on line 23 Call Stack #TimeMemoryFunctionLocation 10.0010252672{main}( )..\edit.php:0 " method="post"> name=
password=
email=

Notice: Undefined index: edit_form in C:\wamp\www\projects\edit.php on line 39

-- Table structure for table `user`

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\projects\edit.php:26) in C:\wamp\www\projects\edit.php on line 46

CREATE TABLE IF NOT EXISTS `user` (
`userid` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`pass` varchar(50) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `email_2` (`email`),
UNIQUE KEY `email_3` (`email`),
UNIQUE KEY `userid` (`userid`),
UNIQUE KEY `email_4` (`email`),
KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=66 ;

--
-- Dumping data for table `user`
--

INSERT INTO `user` (`userid`, `name`, `email`, `pass`, `timestamp`, `id`) VALUES
('59e3950737b1f', 'ram', 'ram@gmail.com', 'rampwd', '2017-10-15 17:04:07', 59),
('59e3a5d94dfbd', 'gaurang', 'gnt3131@gmail.com', 'gaurangpwd', '2017-10-15 18:15:53', 64);


index.php

<html>
<head>
<title></title>

</head>

<body>
<center>
<h1> ADD USER</H1>
<form action="index.php" method="post">
name=<input type ="text" name="name"required/></br>
password=<input type ="text" name="pass" requierd /></br>
email=<input type ="text" name="email" required /></br></BR>
<input type ="submit" name="submit" VALUE ="INSERT"/></br>

</form>
</center>




<?php
$connection=mysqli_connect('localhost','root','root','crud');


if(isset($_POST['submit'])){

$name = $_POST['name'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$userid=uniqid();

if(mysqli_query($connection,"insert into user(userid,name,email,pass)values('$userid','$name','$email','$pass')"))
{
echo"<H2>succesfully insert query</H2>";

}
}
?>

<div align="center">
<table border="2" width="600">
<tr>
<th>USERID</th>
<th>NAME</th>
<th>EMAIL</th>
<th>PASSWORD</th>
<th>DATE CREATED </th>
<th>EDIT</th>
<th>DELETE</th>
</tr></div>
<?php
$connection=mysqli_connect('localhost','root','root','crud');

if(isset($_REQUEST['del'])){
$del_id= $_REQUEST['del'];

if(mysqli_query($connection,"delete from user where id =$del_id"))
{
echo"<h2>selected user of is deleted succesfully";
}





}
$run=mysqli_query($connection,"select * from user");



while($row=mysqli_fetch_array($run))
{

$showuserid=$row[0];
$showname=$row[1];
$showemail=$row[2];
$showpass=$row[3];
$showdate=$row[4];
$showid=$row[5];

echo"<tr>
<td>$showuserid</td>
<td>$showname</td>
<td>$showemail</td>
<td>$showpass</td>
<td>$showdate</td>
<td><a href='edit.php?edit=$showid'>EDIT</td>
<td><a href='?del=$showid'>DELETE</td>
</tr>
";
}




?>
</body>
</html>

-------------------------
edit.php

<?php
$connection=mysqli_connect('localhost','root','root','crud');
$edit=$_REQUEST['edit'];
$run=mysqli_query($connection,"select * from user where id = '$edit'");


while($row=mysqli_fetch_array($run))
{

$name=$row[1];
$email=$row[2];
$pass=$row[3];
$id=$row[5];
}
?>



<html>
<body>
<center>
<h1> EDIT USER</H1>
<form action="edit.php?edit_form =<?php echo $id ?>" method="post">
name=<input type ="text" name="uname" value="<?php echo $name ?>"/></br>
password=<input type ="text" name="upass" value="<?php echo $pass ?>" /></br>
email=<input type ="text" name="uemail" value="<?php echo $email ?>" /></br> </BR>
<input type ="submit" name="uedit" VALUE ="Edit"/></br>

</form>
</center>
</body>
</html>

<?php
$connection=mysqli_connect('localhost','root','root','crud');

if(isset($_POST['uedit']))
{
$uid= $_REQUEST['edit_form'];
$uname= $_POST['uname'];
$upass= $_POST['upass'];
$uemail= $_POST['uemail'];

if(mysqli_query($connection,"update user set name='$uname',email='$uemail',pass='$upass' where id='$uid' "))
{
header("location:index.php");
}
}


----

最佳答案

在您的 edit.php 文件中,将 action="edit.php?edit_form ="更改为 action=""并添加 input type="hidden"name="id"value="' . $id . '";进入您的表格,如下所示...

<?php
$connection = mysqli_connect('localhost', 'root', 'root', 'crud');
$edit = $_REQUEST['edit'];
$run = mysqli_query($connection, "select * from user where id = '$edit'");

while ($row = mysqli_fetch_array($run)) {

$name = $row[1];
$email = $row[2];
$pass = $row[3];
$id = $row[5];
}
?>



<html>
<head>
<title>EDIT USER</title>
</head>
<body>
<center>
<h1> EDIT USER</h1>
<form action="" method="post">
<?php echo '<input type="hidden" name="id" value="' . $id . '">'; ?>
name=<input type ="text" name="uname" value="<?php echo $name ?>"/>
password=<input type ="text" name="upass" value="<?php echo $pass ?>" />
email=<input type ="text" name="uemail" value="<?php echo $email ?>"/>
<input type ="submit" name="uedit" VALUE ="Edit"/>
</form>
</center>
</body>
</html>

<?php
$connection = mysqli_connect('localhost', 'root', 'root', 'crud');
if (isset($_POST['uedit'])) {
$uid = $_POST['id'];
$uname = $_POST['uname'];
$upass = $_POST['upass'];
$uemail = $_POST['uemail'];

if (mysqli_query($connection, "update user set name='$uname',email='$uemail',pass='$upass' where id='$uid' ")) {
header("location:index.php");
}
}
?>

关于php - PHP 中的 CRUD 操作...在 edit.php 中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46759339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com