嗨伙计们,我有一个错误“Undefined index:id”任何人都可以帮助我。谢谢 [英] Hi guys, im having a error "Undefined index: id" anyone can help me about this. thanks

查看:127
本文介绍了嗨伙计们,我有一个错误“Undefined index:id”任何人都可以帮助我。谢谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的错误在这行$ query =DELETE FROM users WHERE id =。$ mysqli-> real_escape_string($ _ GET ['id'])。;



 <   html  >  

< head >

< title > MySQLi删除记录< / title >

< / head >

< 正文 >


// include数据库连接

包括'db_connect.php';

$ action = isset($ _ GET ['action'])? $ _GET ['action']:;

if($ action =='delete'){//如果用户点击确定,运行我们的删除查询

// $ mysqli-> real_escape_string()函数帮助我们防止SQL注入等攻击

$ query =DELETE FROM users WHERE id =。$ mysqli-> real_escape_string($ _ GET ['id'])。;

//执行查询

if($ mysqli-> query($ query)){

//如果成功删除

echo用户已被删除。;

} else {

//如果存在数据库问题

echo数据库错误:无法删除记录。;

}

}

$ query =select * from users;

$ result = $ mysqli-> query($ query);

$ num_results = $ result-> num_rows;

echo< div > < a href = add.php > 创建新记录< / a > < / div > ;

if($ num_results){

echo< border = 1 > ;

echo< tr > ;

echo< th > 名字< / th > ;

echo< th > 姓氏< / th > ;

echo< th > 用户名< / th > ;

echo< th > 操作< / th > ;

echo< / tr > ;

//循环显示每条记录

while($ row = $ result-> fetch_assoc()){

extract($ row) );

echo< tr > ;

echo< td > {$ firstname} < / td > ;

echo< td > <$ span> {$ lastname} < / td > ;

echo< td > <$ span> {$ username} < / td > ;

echo< td > ;

echo< a href = edit.php? id = {$ id} > 编辑< / a > ;

echo/;

//点击我们的删除链接,会出现一个弹出窗口。

//这意味着它运行我们的删除JavaScript

echo< a href = > 删除< / a > ;

echo< / td > ;

echo< / tr > ;

}

echo< / table > ;

} else {

echo未找到任何记录。;

}

$ result-> free();

$ mysqli-> close();

?>

< script 类型 =' text / javascript' >

function delete_user(id){

// 提示用户

var answer = confirm(' 你确定吗?');

如果(回答){ // 如果用户点击确定

// 通过操作重定向到网址as删除记录的删除和ID

window location = ' delete.php?action = delete& id =' + id;

}

}

< / script >

< / body >

< / html > 我的display.php



echo< div > < a href =' add.php' > 创建新记录< < span class =code-leadattribute> / a
> < / div > ;

if($ num_results> 0){//这意味着已有数据库记录

echo< border =' 1' > ; //起始表

//创建我们的表格标题

echo< tr > ;

echo< th > 名字< / th > ;

echo< th > 姓氏< / th > ;

echo< th > 用户名< / th > ;

echo< th > 操作< / th > ;

echo< / tr > ;

//循环显示每条记录

while($ row = $ result-> fetch_assoc()){

//提取行

//这将使$ row ['firstname']变为

//只需$ firstname

extract($ row);

//为每条记录创建新的表格行

echo< tr > ;

echo< td > {$ firstname} < / td > ;

echo< td > <$ span> {$ lastname} < / td > ;

echo< td > <$ span> {$ username} < / td > ;

echo< td > ;

//只需准备编辑链接即可编辑记录

echo< a href = ' edit.php?id = {$ id}' > 编辑< / a > ;

echo/;

//只是准备删除链接以删除记录

echo< a href = ' delete.php' > 删除< / a > ;

echo< / td > ;

echo< / tr > ;

}

echo< / table > ; //结束表

}否则{

//如果数据库表为空

echo未找到记录。;

}

解决方案

query =DELETE FROM users WHERE id =。


mysqli-> real_escape_string(

_GET [ 'ID']) ;



 <   html  >  

< head >

< title > MySQLi删除记录< / title >

< / head >

< 正文 >


//包括数据库连接

包括'db_connect.php';


my error is in this line " $query = "DELETE FROM users WHERE id = ".$mysqli->real_escape_string($_GET['id']).""; "

<html>

<head>

<title>MySQLi Delete Record</title>

</head>

<body>


//include database connection

include 'db_connect.php';

$action = isset($_GET['action']) ? $_GET['action'] : "";

if($action=='delete'){ //if the user clicked ok, run our delete query

//$mysqli->real_escape_string() function helps us prevent attacks such as SQL injection

$query = "DELETE FROM users WHERE id = ".$mysqli->real_escape_string($_GET['id'])."";

//execute query

if( $mysqli->query($query) ){

//if successful deletion

echo "User was deleted.";

}else{

//if there's a database problem

echo "Database Error: Unable to delete record.";

}

}

$query = "select * from users";

$result = $mysqli->query( $query );

$num_results = $result->num_rows;

echo "<div><a href="add.php">Create New Record</a></div>";

if( $num_results ){

echo "<table border="1">";

echo "<tr>";

echo "<th>Firstname</th>";

echo "<th>Lastname</th>";

echo "<th>Username</th>";

echo "<th>Action</th>";

echo "</tr>";

//loop to show each records

while( $row = $result->fetch_assoc() ){

extract($row);

echo "<tr>";

echo "<td>{$firstname}</td>";

echo "<td>{$lastname}</td>";

echo "<td>{$username}</td>";

echo "<td>";

echo "<a href="edit.php?id={$id}">Edit</a>";

echo " / ";

//on click of our delete link, a pop up will appear.

//it means it run our delete JavaScript

echo "<a href="#">Delete</a>";

echo "</td>";

echo "</tr>";

}

echo "</table>";

}else{

echo "No records found.";

}

$result->free();

$mysqli->close();

?>

<script type='text/javascript'>

function delete_user( id ){

//prompt the user

var answer = confirm('Are you sure?');

if ( answer ){ //if user clicked ok

//redirect to url with action as delete and id of the record to be deleted

window.location = 'delete.php?action=delete&id=' + id;

}

}

</script>

</body>

</html>

in my display.php

echo "<div><a href='add.php'>Create New Record</a></div>";

if( $num_results > 0){ //it means there's already a database record

echo "<table border='1'>";//start table

//creating our table heading

echo "<tr>";

echo "<th>Firstname</th>";

echo "<th>Lastname</th>";

echo "<th>Username</th>";

echo "<th>Action</th>";

echo "</tr>";

//loop to show each records

while( $row = $result->fetch_assoc() ){

//extract row

//this will make $row['firstname'] to

//just $firstname only

extract($row);

//creating new table row per record

echo "<tr>";

echo "<td>{$firstname}</td>";

echo "<td>{$lastname}</td>";

echo "<td>{$username}</td>";

echo "<td>";

//just preparing the edit link to edit the record

echo "<a href='edit.php?id={$id}'>Edit</a>";

echo " / ";

//just preparing the delete link to delete the record

echo "<a href='delete.php' >Delete</a>";

echo "</td>";

echo "</tr>";

}

echo "</table>";//end table

}else{

//if database table is empty

echo "No records found.";

}

解决方案

query = "DELETE FROM users WHERE id = ".


mysqli->real_escape_string(


_GET['id']).""; "

<html>

<head>

<title>MySQLi Delete Record</title>

</head>

<body>


//include database connection

include 'db_connect.php';


这篇关于嗨伙计们,我有一个错误“Undefined index:id”任何人都可以帮助我。谢谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆