I have created a page where admins of a site can see and edit their menu navigation items.. As you can see in this image:
So each menu item has two links next to it.. One for deleting the menu item and the other one for updating it.
Basically what I did for updating the menu item is grabbing the id of that item and redirect it to another page called itemedit.php
like this:
<a title='Edit' href='itemedit.php?i=$i'><span class='glyphicon glyphicon-pencil'></span></a>
And in the page itemedit.php
I did this:
<?php
if (isset($_GET['i'])){
$i = $_GET['i'];
$e = // The name that user entered
$editItem = new Menus();
if(isset($_POST['yes'])){
$editItem->EditMenuItem($i,$e);
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=menus.php">';
exit;
}
if(isset($_POST['no'])){
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=menus.php">';
exit;
}
echo "
<section class='content' style='text-align:center;'>
<form action='' method='POST'>
<h5><strong>
Are you sure you want to edit the selected item ?</br></br>
</strong></h5>
<p>
<button name='yes' type='submit' class='btn btn-primary'>Yes</button>
<button name='no' type='submit' class='btn'>No</button>
</p>
</form>
</section>";
So if an admin clicked on "YES" , It should call the Menus
class which goes like this:
I have skipped writing down the db connection and extra information in this class
<?php
class Menus{
public function EditMenuItem($i,$e)
{
if(!empty($i))
{
$adm = $this->db->prepare("UPDATE menu_nav SET menu_link_$i = $e");
$adm->bindParam(1,$i);
$adm->execute();
}
else
{
header("Location: php/includes/errors/012.php");
exit();
}
}
}
?>
Now the problem is I don't know how can I pass the data through the $e variable which contains the new edition of that menu item.
And because I have used a hyperlink rather than an input to redirect my page to itemedit.php
, I cant pass a name attribute. So is there any way or solution to pass this data correctly in itemedit.php
or no ?
<?php
if (isset($_GET['i'])){
$i = $_GET['i'];
$e = // The name that user entered
$editItem = new Menus();