0

这是用户参与的代码。

<html>
<head>
<title></title>
<script src="jquery-1.9.1.js"></script>
<script src="jquery.form.js"></script>
</head>
<body>

<?php

    include 'connection.php';

    $sql="SELECT * FROM blog";

    $result=mysqli_query($link, $sql);
        if(!$result)
            {
                $output='Error fetching students:'.mysqli_error($link);
            }
?>

<div id="table">
<table border='1' cellpadding='10' id="table">

    <tr>
        <td><b>Title<b></td>
        <td><b>Edit<b></td>
        <td><b>Delete<b></td>
    </tr>

    <?php 


        while($row=mysqli_fetch_array($result))
            {
                echo '<tr class="record">';
                echo '<td><a href="#" id="'.$row['articleid'].'" class="title">'.$row['articletitle'] .'</a>';
                echo '<td><a href="#" class="edit">Edit</a>';
                echo "<input type='hidden' name='id' value='".$row['articleid']."'></td>";  
                echo '<td><div align="center"><a href="" id="'.$row['articleid'].'" class="delbutton" title="Click To Delete">Delete</a></div></td>';
                echo "</tr>\n";


            }

    echo '<form method="post" id="myForm" action="postview.php">';
    echo '<input type="hidden" name="myID">';
    echo '</form>';

?>

</table>
<button id="addrecord">Add New Post</button>
</div>


<script type="text/javascript">
$(document).ready(function(){

$("#addrecord").click(function(){
        $("#table").load("addpost.php");
        $("#addrecord").hide();
        });//add

$(".delbutton").click(function(){

//Save the link in a variable called element
    var element = $(this);

//Find the id of the link that was clicked
    var del_id = element.attr("id");

//Built a url to send
    var info = 'id=' + del_id;
    if(confirm("Are you sure you want to delete this Record?"))
        {

            $.ajax({
                        type: "GET",
                        url: "delete.php",
                        data: info,
                        success: function(){}
                    });//ajax

            $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
            .animate({ opacity: "hide" }, "slow");

        }

return false;

});//delete

$(".title").click(function(){
    $('[name=myID]').val($(this).attr('id'));
    $('#myForm').submit();
});//view

$(".edit").click(function(){
    var data=$("#tryform").serialize();

            $.ajax({
                        type: "POST",
                        url: "editpost.php",    
                        data: data
                        }).done(function( msg ) {
                        $("#table").html(msg);
                    });//ajax


});//delete

});


</script>



</body>
</html>

这是上面代码重定向到的 PHP 脚本。

<?php 

include 'connection.php';
$id=$_GET['id'];
echo $id;
$sql="SELECT * FROM blog WHERE articleid='$id'";

$result=mysqli_query($link, $sql);
echo "<table>";

$row=mysqli_fetch_array($result);

echo "<tr>";
echo "<td>".$row['articletitle'] . "</td>";
echo "<td><img src='image.php?id=$row[articleid]' width='200' height='200' /><br/></td>";
echo "<td>".$row['articlemore'] . "</td>";
echo "</tr>";



echo "</table>";
//echo "</div>";
?>

我有这种错误:

未定义索引:第 4 行 C:\xampp\htdocs\ckeditor\samples\postview.php 中的 id

4

4 回答 4

0

那不是错误,而是通知,这是低级的 它简单意味着$_GET['id']没有值

echo $example['something']; // will give undefined index notice
$example['something'] = 'abc';
echo $example['something']; // No notices

你的网站应该是domain.ext/?id=123,如果没有,这个通知会显示。

于 2013-09-12T13:46:25.633 回答
0

与其说是对您的问题的回答,不如说是使您的代码更干净的好建议-尝试使用PHP Alternative Syntax并移入和移出 PHP 以使您的 HTML 干净。

<?php while($row=mysqli_fetch_array($result)):?>
                <tr class="record">';
                    <td><a href="#" id="<?php echo $row['articleid'];?>" class="title"><?php echo $row['articletitle'];?></a>
                    <td><a href="#" class="edit">Edit</a>
                        <input type='hidden' name='id' value='<?php echo $row['articleid'];?>'></td>
                    <td>
                        <div align="center">
                            <a href="" id="<?php echo $row['articleid'];?>" class="delbutton" title="Click To Delete">Delete</a>
                        </div>
                    </td>
                </tr>
<?php endwhile;?>

<form method="post" id="myForm" action="postview.php">
    <input type="hidden" name="myID">
</form>
于 2013-09-12T13:48:48.787 回答
0

您需要先检查参数“id”是否传递给 php 脚本

<?php 

include 'connection.php';
if( (isset($_GET['id'])) && ($_GET['id'] != '') ){ //check if the argument "id" is passed to the script
    $id=$_GET['id'];
    echo $id;
    $sql="SELECT * FROM blog WHERE articleid='$id'";

    $result=mysqli_query($link, $sql);
    echo "<table>";

    $row=mysqli_fetch_array($result);

    echo "<tr>";
    echo "<td>".$row['articletitle'] . "</td>";
    echo "<td><img src='image.php?id=$row[articleid]' width='200' height='200' /><br/></td>";
    echo "<td>".$row['articlemore'] . "</td>";
    echo "</tr>";



    echo "</table>";
//echo "</div>";
}

?>
于 2013-09-12T13:48:03.987 回答
0
$sql="SELECT * FROM blog WHERE articleid='".$id."'";

试试这条线

于 2013-09-12T13:56:20.767 回答