Created
February 26, 2014 07:32
-
-
Save reshadman/9225217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# start session | |
session_start(); | |
# if logged in name else make the name FALSE to make an access denied redirect | |
$name = (empty($_SESSION['username'])?false:$_SESSION['username']); | |
# Redirect if not logged in | |
if (!$name) | |
{ | |
header("location:../admin/login admin.html"); | |
exit(); | |
} | |
# raw query | |
$query = "SELECT * | |
FROM `posts` | |
WHERE `namee` = '$name'"; | |
# Get results | |
$result = mysql_query($query); | |
# Nothing found if there is no records matching the username | |
if (is_null($result)) | |
{ | |
print '<p style="text-align:center"> There is no result for user ' . $name ' .'; | |
exit(); | |
} | |
# Fetch records to an array | |
$records = mysql_fetch_assoc($result); | |
foreach ($records as $id => $record) | |
{ | |
/** | |
* Field haye mojood dar database: | |
* 1. Title: title | |
* 2. ID : id | |
* 3. Body: body | |
* | |
* Baraye delete/edit kardan ya virayesh kardan niyaz be ye safe darid ke | |
* ba id record be script dade mishe maslane: | |
* URL to delete : http://yoursite.com/url/to/edit.php?edit_id=4 | |
* dar mesale bala 4 id database baraye delete/edit hast | |
* too safeye jadid ye form dorost konid be hamin URL mesal dar bala ba method POST | |
* va meghdare title va body ro dar dakhele INPUT ('text' ya 'textarea') neshoon bedin | |
* Varablae : $record['title'], $record['id'],$record['body'] | |
*/ | |
print ' | |
<div class="post"> | |
<h1 clss="title"> ' . $record['title'] . '</h1> | |
<span class="eidt-or-delete"><a href="url/to/edit/?edit_id=' . $record[$id] . '">ویرایش یا حذف</a></span> | |
<p class="body"> | |
' . $record['body'] . ' | |
</p> | |
</div> | |
'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment