<?php $con= mysql_connect("localhost","root","pritam"); if (!$con) { die("Can not connect: " . mysql_error()); } mysql_select_db("new_blog",$con); if(isset($_POST['update'])) { $UpdateQuery = "UPDATE user_posts SET title='$_POST[title]', body='$_POST[body]' where post_id='$_POST[hidden]'"; mysql_query($UpdateQuery, $con); echo "<script type='text/javascript'> alert('Post Successfully Modified') </script>"; }; if(isset($_POST['delete'])) { $DeleteQuery = "DELETE FROM user_posts where post_id='$_POST[hidden]'"; mysql_query($DeleteQuery, $con); echo "<script type='text/javascript'> alert('Post Successfully Deleted') </script>"; }; $sql = "SELECT * FROM user_posts"; $myData = mysql_query($sql,$con); echo "<table id=blog_post > <tr> <th style='font-size:25px;'>Title</th> <th style='font-size:25px;'>Body</th> <th colspan=2 style='font-size:25px;'>Operation</th> </tr>"; while($record = mysql_fetch_array($myData)) { echo "<form action=Add_Update_Delete_Post.php method=post>"; echo "<tr>"; echo "<td>" . "<input type='text' style='width:300px; height:30px; font-size:18px;' name='title' value=" . $record['title'] . "/> </td>"; echo "<td>" . "<textarea rows=10 cols=60 name='body' value=" . $record['body'] . " /></textarea></td>"; echo "<td>" . "<input type='submit' name='update' value='Modify' style='width:200px; height:35px; font-size:16px;'>" . " </td>"; echo "<td>" . "<input type='submit' name='delete' value='Delete' style='width:200px; height:35px; font-size:16px;'>" . " </td>"; echo "<td>" . "<input type='hidden' style='border:0;' name='hidden' value=" . $record['post_id'] . " </td>"; echo "</tr>"; echo "</form>"; } echo "</table>"; mysql_close($con); ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)