I have here an integrated version of my code into a modal...
This code gives undefined index id
<!-- Edit-Page Modal -->
<div class="modal fade" id="edit-pages" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Edit Page</h4>
</div>
<div class="modal-body">
<?php
//check for any errors
if(isset($error)){
foreach($error as $error){
echo $error.'<br />';
}
}
try {
$qp = $db->prepare('SELECT PageID, PageName, Content FROM pages WHERE pageID = :pageID') ;
$qp->execute(array(':pageID' => $_GET['id']));
$row = $qp->fetch();
} catch(PDOException $e) {
echo $e->getMessage();
}
?>
<form action='' method='POST'>
<input type='hidden' name='pageID' value='<?php echo $row['PageID'];?>'>
<p><label>Content</label><br />
<textarea name='Content' cols='60' rows='10'><?php echo $row['Content'];?></textarea></p>
<script>
CKEDITOR.replace( 'Content',{customConfig:'/config.js'});
</script>
<p><input class="btn btn-primary btn" type='submit' name='submitpage' value='Update'></p>
<?php include("../includes/submitpage.php");?>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- END Page MODAL -->
Here is submitpage.php that doesnt insert or update the content on the database
<?php
//if form has been submitted process it
if(isset($_POST['submitpage'])){
//collect form data
extract($_POST);
//very basic validation
if($pageID ==''){
$error[] = 'This page is missing a valid id!.';
}
if($Content ==''){
$error[] = 'Please enter the content of the page.';
}
if(!isset($error)){
try {
$query = 'SELECT fullname from members where idNUMBER="'.$_SESSION['idnumber'].'"';
try {
$pdoStatement = $db->query($query);
}
catch (PDOException $exception) {
// the query failed and debugging is enabled
echo "<p>There was an error in query: $query</p>";
echo $exception->getMessage();
$pdoStatement = false;
}
if ($pdoStatement) {
// the query was successful
// get the result (if any)
// fetchObject returns FALSE if there is no record
if ($recordObj = $pdoStatement->fetchObject()) {
$user=$recordObj->fullname;
$act= "Edited page ".$pageName;
$addcat=$db->prepare('INSERT INTO userlog (Name, Datelog, Activity ) VALUES (:Name, :Datelog, :Activity)') ;
$addcat->execute(array(
':Name' => $user,
':Datelog' => date('Y-m-d H:i:s'),
':Activity'=> $act
));
}
}
//insert into database
$insp = $db->prepare('INSERT into pages (Content) VALUES (:Content)');
$insp->execute(array(
':Content' => $Content
));
//redirect to Main Panel page
header('Location: MainPanel.php');
exit;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
}
?>
Lastly, is this code
<!-- Tab panes -->
<div class="tab-content">
<!-- Pages -->
<div class="tab-pane active" id="pages">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Page</th>
<th>Options</th>
</tr>
</thead>
<?php
try {
//instantiate the class
$pages = new Paginator('3','p');
//collect all records for the next function
$stmt = $db->query('SELECT pageID FROM pages');
//determine the total number of records
$pages->set_total($stmt->rowCount());
$stmt = $db->query('SELECT pageID, pageName FROM pages ORDER BY pageID ASC '.$pages->get_limit());
while($row = $stmt->fetch()){
echo ' <tbody>
<tr>
<td>'.$row['pageID'].'</td>
<td>'.$row['pageName'].'</td>'
?>
<td><a href="#edit-pages?id=<?php echo $row['pageID'];?>" data-toggle="modal" data-target="#edit-pages">Edit</a> </td>
</tr>
<?php
}
echo '<div>'.$pages->page_links().'</div>';
}catch(PDOException $e) {
echo $e->getMessage();
}
?>
</table>
</div>
<!-- Pages end -->