状态delete.php函数
我的按钮正在工作,当我单击状态上的 X 按钮时,它需要我删除。php 向我显示浏览器中的链接和streamitem_id 编号,如下所示。
这是按钮
echo '<a href="mysiteraw/sn-extend/theme/default/delete.php?='.$streamitem_data['streamitem_id'].'" onclick="show_confirm() alt="Delete" title="Delete" class="delete">X</a> ';
及其给出的链接
我的网站 /raw/sn-extend/theme/default/delete.php?=1516
然后我在这个页面上看到“找不到评论”那么有人可以帮我删除delete.php页面吗?
这是我的 SQL
如果表不存在则创建
on_streamdata
(streamitem_id
int(11) NOT NULL 自动增量,streamitem_type_id
int(11) NOT NULL,streamitem_creator
int(11) NOT NULL,streamitem_target
int(11) NOT NULL,streamitem_timestamp
日期时间 NOT NULL,streamitem_content
varchar(5000) NOT NULL,streamitem_public
int(11) NOT NULL,streamitem_interactionallowed
int(11) NOT NULL 默认 '1',streamitem_isgroupie
int(11) NOT NULL 默认“1”,streamitem_viaid
int(11) NOT NULL 默认 '0',
主键(streamitem_id
)) 引擎=MyISAM 默认字符集=latin1 自动增量=1953;
这是我的delete.php,这可能是完全错误的,因为我是 PHP/MySql 的新手..抱歉
<?php
error_reporting (E_ALL ^ E_NOTICE);
$id=$_GET['id'];
$ipuser=getenv('REMOTE_ADDR');
//Connect to server and select databse.
mysql_connect("localhost", "", "")or die("cannot connect to server");
mysql_select_db("")or die("cannot select DB");;
$querycheck="SELECT streamitem_id FROM on_streamdata WHERE streamitem_id='$id'";
$resultcheck=mysql_query($querycheck);
$num=mysql_numrows($resultcheck);
if ($num==0) {
?>
<br>Comment not found.<br>
<br><br>
<a href="javascript: history.go(-1)">Back</a><br>
<?
} else {
$ip=mysql_result($resultcheck,0,"streamitem_id");
if ($ip==$ipuser) {
?>
<form method="post">
<p align="center">
Are you sure you want to delete this comment?
<input type="hidden" name="confirm" value="1">
<br>
<input type="Submit" value="Delete">
</form>
<?
$confirm=$_POST['confirm'];
if ($confirm==1) {
$query=" DELETE streamitem_id FROM on_streamdata WHERE streamitem_id='$id'";
mysql_query($query);
echo "<br>Comment Deleted.<br>";
?>
<br><br>
<a href="javascript: history.go(-2)">Back</a><br>
<?
} else {
?>
<br><br>
<a href="javascript: history.go(-1)">Back</a><br>
<?
}
} else {
?>
<br>You are not allowed to delete this comment.<br>
<br><br>
<a href="javascript: history.go(-1)">Back</a><br>
<?
}
}
mysql_close();
I have the button working, when I click the X button on my status it takes me to delete.php shows me the link in the browser and the streamitem_id number like so.
Here is the button
echo '<a href="mysiteraw/sn-extend/theme/default/delete.php?='.$streamitem_data['streamitem_id'].'" onclick="show_confirm() alt="Delete" title="Delete" class="delete">X</a> ';
And the link it gives out
my site
/raw/sn-extend/theme/default/delete.php?=1516
I then see on this page 'cannot find comment' So can anyone help me with the delete.php page please?
Here is my SQL
CREATE TABLE IF NOT EXISTS
on_streamdata
(streamitem_id
int(11) NOT NULL auto_increment,streamitem_type_id
int(11) NOT NULL,streamitem_creator
int(11) NOT NULL,streamitem_target
int(11) NOT NULL,streamitem_timestamp
datetime NOT
NULL,streamitem_content
varchar(5000) NOT NULL,streamitem_public
int(11) NOT NULL,streamitem_interactionallowed
int(11) NOT NULL default '1',streamitem_isgroupie
int(11) NOT
NULL default '1',streamitem_viaid
int(11) NOT NULL default '0',
PRIMARY KEY (streamitem_id
) )
ENGINE=MyISAM DEFAULT CHARSET=latin1
AUTO_INCREMENT=1953 ;
And here is my delete.php which is probably completely wrong as I'm new to PHP/MySql..Sorry
<?php
error_reporting (E_ALL ^ E_NOTICE);
$id=$_GET['id'];
$ipuser=getenv('REMOTE_ADDR');
//Connect to server and select databse.
mysql_connect("localhost", "", "")or die("cannot connect to server");
mysql_select_db("")or die("cannot select DB");;
$querycheck="SELECT streamitem_id FROM on_streamdata WHERE streamitem_id='$id'";
$resultcheck=mysql_query($querycheck);
$num=mysql_numrows($resultcheck);
if ($num==0) {
?>
<br>Comment not found.<br>
<br><br>
<a href="javascript: history.go(-1)">Back</a><br>
<?
} else {
$ip=mysql_result($resultcheck,0,"streamitem_id");
if ($ip==$ipuser) {
?>
<form method="post">
<p align="center">
Are you sure you want to delete this comment?
<input type="hidden" name="confirm" value="1">
<br>
<input type="Submit" value="Delete">
</form>
<?
$confirm=$_POST['confirm'];
if ($confirm==1) {
$query=" DELETE streamitem_id FROM on_streamdata WHERE streamitem_id='$id'";
mysql_query($query);
echo "<br>Comment Deleted.<br>";
?>
<br><br>
<a href="javascript: history.go(-2)">Back</a><br>
<?
} else {
?>
<br><br>
<a href="javascript: history.go(-1)">Back</a><br>
<?
}
} else {
?>
<br>You are not allowed to delete this comment.<br>
<br><br>
<a href="javascript: history.go(-1)">Back</a><br>
<?
}
}
mysql_close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,首先您不要通过此处的 url 查询字符串传递任何变量
提示:在下一页您搜索
$_GET['id']
,所以我认为您应该输入id< /code> 而不是上面示例中的
PUT_SOME_NAME_HERE
:)尝试一下并分享结果。
在您的代码示例中,还缺少数据库选择和 mysql 用户/密码的传递。您是否故意删除它们只是为了不在此处显示敏感信息?
Ok, first you don't pass any variable via the url query string here
Hint: on next page you search for
$_GET['id']
, so I presume you should putid
instead ofPUT_SOME_NAME_HERE
in above example :)Try that and share results.
In your code example, there is also missing database selection and passing of mysql user/password. Do you remove them in purpose just to not show sensitive information here?
$querycheck="SELECT streamitem_id FROM on_streamdata WHERE streamitem_id='$id'";
您的表名称实际上是
on_groups_streamdata
另外,您需要清理并验证您的输入,或者使用磷酸二氢钾
$querycheck="SELECT streamitem_id FROM on_streamdata WHERE streamitem_id='$id'";
your table name is actually
on_groups_streamdata
also, you need to sanitize and validate your input, or use PDO