dongwei2983 2012-08-06 17:07
浏览 26

每个帖子后更新按钮(php,sql)

I need some help with PHP and SQL. Have looked for help in older questions and answers here but can't find anyting like my problem. I'm doing a webbsite where you can post notes in different subjects (Work, Home, School, and so on). After every note that being selected from my database I have a delete button that deletes the selected note.

Now I want to add a change/update button next to the delete button. When pressing the update button I want to be redirected to another page (update.php for example) where that original note is, ready to type in something new or change the note. Then pressing another update button that sends and replace the note at my database table. I have no idea how to to that and would be so grateful for all the help I can get.

This is my code that shows all the current posts for the subject work and where the update button should be next to the delete button.

<?php 

if(isset($_POST['delete'])){
   $id = $_POST['delete_rec_id'];  
   $query = "DELETE FROM notes WHERE id=$id"; 
   $result = mysql_query($query);
}

$query = "SELECT * FROM notes WHERE subject='Work' order by id desc";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) { 
        $id = $row['id'];
        $subject = $row['subject'];
        $date = $row['date'];
        $note = $row['note']; 

        print "<p><strong>$subject</strong> ($id), $date </p>"; 
        print "<p> $note </p>";

    ?>
    //delete button starts here here
    <form id="delete" method="post" action="">
    <input type="hidden" name="delete_rec_id" value="<?php print $id; ?>"/> 
    <input type="submit" name="delete" value="Delete!"/>  
    </form>
    //THIS IS WHERE THE DELETE BUTTON SHOULD BE
    <?php
}   
?>

So grateful for any help i can get :)

  • 写回答

1条回答 默认 最新

  • duancuo1234 2012-08-06 21:59
    关注

    Basicly, the update button will just redirect the user to another page. So:

    <form id="delete" method="post" action="">
    <input type="hidden" name="delete_rec_id" value="<?php print $id; ?>"/> 
    <input type="submit" name="delete" value="Delete!"/>  
    </form>
    <input type="button" name="redirect<?php print $id; ?>" value="Update" onClick="location.href( 'http://www.domain.com/update.php?id=<?php print $id; ?>');"/>
    

    In your update.php file you just use $_GET to access the ID of the row.

    $id =$_GET['id'];
    echo "You want to edit the row with ID = ".$id;
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度