Jump to content

Merging Two Files


.Darkman

Recommended Posts

Hello All,

 

I have a blog system. And i have a simple Admin Panel.

 

I have one file called "manage_categories.php"

 

It is :

<?php

$query = "SELECT id, title FROM categories";
$result = @mysql_query($query);

if ($result) {
echo '<div align="center">
<table border="0">
<tr>
<td><b>ID</b></td>
<td><b>Title</b></td>
<td><b>Delete</b></td>
<td><b>Edit</b></td>
</tr>';

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr>
<td>'.$row['id'].'</td>
<td>'.$row['title'].'</td>
<td><a href="delete_category.php?id='.$row['id'].'">Delete</a></td>
<td><a href="edit_category.php?id='.$row['id'].'">Edit
</tr>';
}
} else {
echo 'Sorry, but we could not retrieve any categories.';
}
?>
</table>
</div>

 

That displays all the links to edit and delete them.

 

I have the "delete_category.php" as : -

<?php

include ('login_check.php');

if (isset($_GET['id'])) {
include('../includes/mysql_connect.php');
if (is_numeric($_GET['id'])) {
$id = $_GET['id'];

$query = "DELETE FROM categories WHERE id = $id";
$result = mysql_query($query);

include ('header.php');

if ($result) {
echo '<h3>Success!</h3><br />
The Category was deleted succesfully.<br /><br />';
} else {
echo 'We are sorry to inform you but the Category you chose to delete could not be deleted. Please feel free to try again';
}
} else {
echo 'Invalid category, please choose a news item.';
}
} else {
echo 'Before visiting this page please choose a category to delete first!';
}
?>
<?php include ('footer.php'); ?>

 

Now what i'd like to do is, merge both of these files into one single file.

 

Also i'd like to say that the manage_categories.php is not accessbile through : http://myadmin.com/manage_categories.php

 

It is accessible only through http://myadmin.com/manage.php?type=category

 

Please do help me with this.

I'd also like my edit_categories.php to be merged with these too.

 

 

Thanks,

 

 

Link to comment
https://forums.phpfreaks.com/topic/41917-merging-two-files/
Share on other sites

put the contents of delete file at top of manage file and encapsulate in an if statement like

if($_GET[action] == "delete"){

 

delete file contents here

 

}

 

and change your delete links to

 

<a href="?manage_categories.php&action=delete&id='.$row['id'].'"

 

mimic the same schema for edit categories

Link to comment
https://forums.phpfreaks.com/topic/41917-merging-two-files/#findComment-203250
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.