PHP Notification Page - Table not displaying Results - php

I've created a notification script and I have a page called notificationCenter.php where the admin user can view ALL the notifications. It will display which users have read which notifications, when it was posted and who by. Everything works fine with it, the only issue is when I go onto the notificationCenter.php page to view all notifications, the table doesn't display the results. However I run an if statement to check if there are any results and I don't get any errors. Here's my code, I'm sure I've done something stupid but I can't see what it is, I'd really appreciate any help!.
//Get User ID
$id = $_SESSION['user_id'];
//Select * Notifications
$notQuery = $serviceConn->query("SELECT * FROM db759709251.notifications WHERE `not_viewedby` NOT LIKE '%$id%' ");
<h4>Nofication Center</h4>
<?php if($notQuery->rowCount()) { ?>
<table>
<thead>
<tr>
<th scope="col">Status</th>
<th scope="col">User</th>
<th scope="col">Notification</th>
<th scope="col">Date</th>
<th scope="col">Viewed By</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php
while ($row = $notQuery->fetch()) {
$notid = $row['not_id'];
$notUser = $row['not_user'];
$notMsg = $row['not_msg'];
$notStatus = $row['not_status'];
$notDate = $row['not_date'];
$notViewedby = $row['not_viewedby'];
?>
<tr>
<td style="background-color: <?php echo $statusColour; ?>" data-label="Status"><?php echo $notStatus; ?></td>
<td data-label="User"><?php echo $notUser; ?></td>
<td data-label="Notification"><?php echo $notMsg; ?></td>
<td data-label="Date"><?php echo $notDate; ?></td>
<td data-label="Viewed By"><?php echo $notViewedby; ?></td>
<td data-label="">
<form action="" method="POST">
<input type="hidden" name="notificationID" value="<?php echo $notid; ?>" >
<input type="hidden" name="notificationBy" value="<?php echo $notViewedby; ?>">
<input type="submit" name="read" value="Dismiss!">
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php } else { ?>
<p>You currently have no notifications, please check back later.</p>
<?php } ?>
Now obviously there is a lot of HTML in the middle for styling and layouts, but I didn't think it was important enough as it shouldn't have any effect on the output of the table. But as you can see the if statement SHOULD print that there are no notifications and to check back later, and it doesn't so in theory there should be records to display.

Related

button to send multiple data to the database (php, ajax)

I send the data from the database to the screen with foreach.I do not see any results when I click the button.where do i make mistakes i ask you to help
<table class="table">
<thead class="thead-dark" align="center" >
<th >id</th>
<th >EğitimAdı</th>
<th >Adres</th>
<th >Onay </th>
</thead>
<tbody>
<form id="form1" action="" method="post">
<?php $i=1; foreach($dbb as $ac){ ; ?>
<tr align="center" >
<td > <?php echo $ac[0]; ?> </td>
<td > <?php echo $ac[1]; ?></td>
<td align="center"> <iframe width="360" height="115" src="<?php echo $ac[2]; ?>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen ></iframe></td>
<td >
<button type="button" value="<?php echo $ac[0]; ?>" id="gonder" onclick="gonder('this.val()')">İzledim</button>
</td>
</tr>
<?php $i++; } ?>
</form> <p></p>
</tbody>
</table>
gonder.js send to the database
function gonder(deger){
$.ajax({
type:"post",
url:"isleme.php",
data:deger,
success:function(cevap) {
$("p").text(cevap);
}
})
}
isleme.php to view the screen
<?php
$b=$_POST['deger'];
echo $b;
?>
First you're missing parentheses:
onclick="gonder" has to be onclick="gonder()"
Secondly variable "deger" is empty because #id doesn't exist, try changing to:
var deger = $("#gonder").val();
I noticed you are iterating and having same id for all the elements. Ideally id should be unique in each of the document.
You can do either of the below:
prepare and have unique id for each iterative element.
Try removing id element since you are not dependent on click using id.
Please let me know, if it helps?

Passing Form Data to separate PHP Page

I have a table with multiple columns (index.php). One column is a checkbox. Whenever the checkbox is checked, it displays another row where you can select a quantity. You can then hit a button called "Add to Order" and it will take you to a confirmation page (index-order.php) where I want it to display each row along with all of the data in that specified row that has the checkbox checked. Currently, I am getting no errors in my console, but no data is being displayed at all.
What do I need to change to make this happen? Here is what I have so far.
Index.php code:
<form name="form1" method="POST" action="index-order.php">
<section id="addToOrder">
<button type="submit" class="order" id="order" name="order" value="AddToOrder">Add to Order</button>
</section>
<br>
<div id="my-div2" class="ui-widget">
<div class="ui-widget">
<table id="merchTable" cellspacing="5" class="sortable">
<thead>
<tr class="ui-widget-header">
<th class="sorttable_nosort"></th>
<th class="sorttable_nosort">Loc</th>
<th class="merchRow">Report Code</th>
<th class="merchRow">SKU</th>
<th class="merchRow">Special ID</th>
<th class="merchRow">Description</th>
<th class="merchRow">Quantity</th>
<th class="sorttable_nosort">Unit</th>
<th style="display: none;" class="num">Quantity #</th>
</tr>
</thead>
<tbody>
<?php foreach ($dbh->query($query) as $row) {?>
<tr>
<td class="ui-widget-content"><input type="checkbox" class="check" name="check"></td>
<td name="rows[0][0][loc]" class="loc ui-widget-content" id="loc-<?php echo intval ($row['Loc'])?>"><?php echo $row['Loc'];?></td>
<td name="rows[0][0][rp-code]" class="rp-code ui-widget-content" align="center" id="rp-code-<?php echo intval ($row['Rp-Code'])?>"><?php echo $row['Rp-Code'];?></td>
<td name="rows[0][0][sku]" class="sku ui-widget-content" id="sku-<?php echo intval ($row['SKU'])?>"><?php echo $row['SKU'];?></td>
<td name="rows[0][0][special-id]" class="special-id ui-widget-content" align="center" id="special-id-<?php echo intval ($row['Special-ID'])?>"><?php echo $row['Special-ID'];?></td>
<td name="rows[0][0][description]" class="description ui-widget-content" id="description-<?php echo intval ($row['Description'])?>"><?php echo $row['Description'];?></td>
<td name="rows[0][0][quantity]" class="quantity ui-widget-content" data-quantity="<?php echo $row['Quantity'] ?>" align="center" id="quantity-<?php echo intval ($row['Quantity'])?>"><?php echo $row['Quantity'];?></td>
<td name="rows[0][0][unit]" class="unit ui-widget-content" id="unit-<?php echo intval ($row['Unit'])?>"><?php echo $row['Unit'];?></td>
<td name="rows[0][0][quant]" style="display: none;" class="quantity_num ui-widget-content"><input type="textbox" style="width: 100px;" class="spinner" name="value" id="test"></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</form>
Index-order.php:
<?php if(isset($_POST['rows'])): ?>
<table cellspacing="20">
<tr align="center">
<th>Loc</th>
<th>Report Code</th>
<th>SKU</th>
<th>Special ID</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit</th>
<th>Quantity #</th>
</tr>
<?php
foreach($_POST['rows'][0] as $row):
?>
<tr align="center">
<td><?php echo $row['loc']; ?></td>
<td><?php echo $row['rp-code']; ?></td>
<td><?php echo $row['sku']; ?></td>
<td><?php echo $row['special-id']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quant']; ?></td>
</tr>
<?php
endforeach;
?>
</table>
I am okay with the precedent answer, I never heard about this kind of method with PHP and it doesn't seems to be the right solution. Anyway, the following post would maybe help you : How to get value from td's via $_POST.
You cannot transfer datas through POST by using td ; but an alternative would be to use the "hidden" type of forms element :
<form action="script.php" method="post">
<td class=".."><input type="hidden" name="td1" value="...">value</td>
...
</form>
In PHP, you'll grab the data with the $_POST array and the td1 name :
<?php var_dump($_POST); ?>
Itwould in my opinion be the easier way to get what you want in a proper way ; the link I gave upper is also talking about DOMDocument, but it looks more complex to manage with.

ajaxForm 500 Internal Server Error

Hi im making an ajaxForm using comments.My problem is why the error is 500 Internal Server Error???, Well my codes and js library are in there, i dont quite understand why 500 internal server error.. Here's my code below.
<script>
$(document).ready(function(){
$("#tbl_comments").hide();
//$("#loading").hide();
$("#ptxt_green").hide();
$('#comment_form').ajaxForm({
target: '.result',
beforeSubmit: validate,
success: function(data) {
alert(data);
}
});
$("#loading")
.hide()
$(".result").show()
.ajaxStart(function(){
$(this).show();
$(".result").hide();
$("#loading").show();
})
.ajaxStop(function(){
$(this).hide();
$(".result").show();
})
;
});
function validate(){
var comment = $('textarea[name=txt_comment]').fieldValue();
if(!comment[0]){
$("#ptxt_green").fadeIn();
$("#ptxt_green").fadeOut(3000);
return false;
}
}
</script>
<?php $sf_response->setTitle(myTitleFactory::getPageTitle('seminar_detail', 'frontend',array('%seminar_title%'=>$seminar->getTitle())));?>
<?php myTools::loadBreadSlot(array(
myBreadcrumbFactory::get('seminar-list', 'frontend'),
myBreadcrumbFactory::get('seminar', 'frontend', array('slug' => $seminar->getSlug()), $seminar->getTitle())))
?>
<h1><?php echo $seminar->getTitle(); ?></h1>
<div class="table_seminar_wrap">
<table class="table_seminar" cellspacing="0" cellpadding="0" border="0" summary="info table">
<tr>
<th>Employee Id</th>
<td><?php echo $seminar->getId(); ?></td>
</tr>
<tr>
<th valign="top">情報公開日</th>
<td><?php echo $seminar->getPublishDate() .' '.$seminar->getPublishHour(); ?>時</td>
</tr>
<tr>
<th valign="top">セミナースキーム</th>
<td><?php echo $seminar->getStyle(); ?></td>
</tr>
<tr>
<th valign="top">日程</th>
<td><?php echo $seminar->getSeminarDate() .' '.$seminar->getStartTime() .' ~'.$seminar->getEndTime(); ?></td>
</tr>
<tr>
<th valign="top">前振りの文章</th>
<td><?php echo $seminar->getRawValue()->getSummary(); ?></td>
</tr>
<tr>
<th valign="top">タイトル</th>
<td><?php echo $seminar->getTitle(); ?></td>
</tr>
<tr>
<th valign="top">サブタイトル</th>
<td><?php echo $seminar->getSubTitle(); ?></td>
</tr>
<tr>
<th valign="top">開催地</th>
<td><?php echo $seminar->_getAddress(ESC_RAW); ?></td>
</tr>
<tr>
<th valign="top">会場</th>
<td>
<?php if($seminar->getLocationName()) : ?>
<?php echo $seminar->getLocationName(); ?><br>
<?php endif; ?>
<?php if($seminar->getRoomName()) : ?>
<?php echo $seminar->getRoomName(); ?>
<?php endif; ?>
</td>
</tr>
<?php if($seminar->getLocationName()) : ?>
<tr>
<th valign="top">会場URL</th>
<td><?php echo $seminar->getLocationUrl(); ?></td>
</tr>
<?php endif; ?>
<tr>
<th valign="top">内容</th>
<td><?php echo $seminar->getRawValue()->getDetail(); ?></td>
</tr>
<tr>
<th valign="top">キーチャート</th>
<td>
<?php if($seminar->getImagePath()): ?>
<a href="<?php echo $seminar->getImagePath(); ?>" target="_blank">
<img style="width:300px;" src="<?php echo $seminar->getImagePath(); ?>"/></a>
<?php endif; ?>
</td>
</tr>
<tr>
<th valign="top">対象</th>
<td>
<?php foreach($seminar->getTarget() as $target): ?>
<?php echo $target; ?>
<?php endforeach;?>
</td>
</tr>
<tr>
<th valign="top">定員・残席状況</th>
<td><?php echo $seminar->getCapacity(); ?>人</td>
</tr>
<tr>
<th valign="top">参加料</th>
<td><?php echo $seminar->getPrice(); ?></td>
</tr>
<tr>
<th valign="top">担当者</th>
<td><?php echo $seminar->getEmployee()->getName(); ?></td>
</tr>
<tr>
<th valign="top">講師</th>
<td>
<img class="instructorImage" alt="Instructor Image" src="<?php echo $seminar->getInstructor()->_getImagePath(); ?>" /><br>
<span><?php echo $seminar->getInstructor()->getName(); ?><span>
</td>
</tr>
<tr>
<th valign="top" style="width:170px">ご参加の皆様へのメッセージ</th>
<td><?php echo $seminar->getRawValue()->getMessage(); ?></td>
</tr>
<?php if($sf_user->isAuthenticated() && !$seminarXPerson): ?>
<tr>
<td style="text-align:center;" colspan="2">
<div class="blueBtnLink">
<span>応募する</span>
</div>
</td>
</tr>
<?php elseif(!$sf_user->isAuthenticated()): ?>
<tr>
<td style="text-align:center;" colspan="2">
<div class="blueBtnLink">
<span>応募する</span>
</div>
</td>
</tr>
<?php endif; ?>
</table>
<div id="ptxt_green">
<p>Please Write A Comments. . .</p>
</div>
<br />
<?php if($sf_user->isAuthenticated()): ?>
<form id="comment_form" action="<?php echo url_for('seminar/comment');?>" method="post">
<textarea id="txt_comment" name="txt_comment"></textarea>
<input type="submit" value="Write Comments" />
<br />
<br />
<div id="loading" style="text-align:center;">
<img alt="" src="/images/loading.gif" />
</div>
<div class="result">
<table id="tbl_comments">
<tr>
<td width="10%">Comments:</td>
<td>asasa</td>
</tr>
</table>
</div>
</form>
<?php endif; ?>
</div>
and my php file is this one
<?php
class commentAction extends sfAction{
public function execute($request){
echo "test"; exit();
//echo "qwqqwqqw"; exit();
//$post = $request->getParameter('seminar');
////print_r($post);exit();
//$comment = new SeminarComments();
//$comment->setComments($post['txt_comment']);
//$comment->save();
//$this->redirect('seminar');
}
}
?>
there.Why 500 internal server error? is this from the js? error?
neeeeeeeeeeed badly help
You have not provided enough info for anyone to give you a definitive answer, but here are some troubleshooting tips:
Check your server logs. To find where they are, see https://serverfault.com/questions/287079/cant-find-apache-error-logs and try to grep it out, here are a few to try (stolen directly from referenced ServerFault question)
grep ErrorLog /usr/local/etc/apache22/httpd.conf
grep ErrorLog /etc/apache2/apache2.conf
grep ErrorLog /etc/httpd/conf/httpd.conf
Once you find your server logs, find the log entry that corresponds to your 500 error. If you are having a hard time finding it, make another request with your client and then try to find the latest log entries.
Possible sources of error in your JavaScript include:
Calling the wrong URL
Calling the right URL but with the wrong parameters
Calling the right URL and parameters but with the wrong format (ie JSON vs XML)
Calling the right URL, parameters, and format but with wrong method (ie GET vs POST)
Calling the right URL/parameters/format/method but sending bogus data that the web server rejects (ie some servers are configured to automatically reject certain strings that look malicious)
By the way the server-side code you have posted does not tell the whole story. It is a simple class but rests on top of a complex framework, and you need to check the framework configuration to see if all is well. In particular, try calling the action directly (ie in your web browser, NOT through jQuery/JS). If it doesn't work, try calling a different action and see if it works. If you cannot get any action to work, it might be a framework config issue. I'm not familiar with symfony but if I were forced to become so I would start there.
If you can provide us the error log it would help greatly.
Try to call dev controller from your ajaxCall.
Normally you call index.php which is production controller and it doesn't provide any useful information about the error. Try to call front_dev.php instead which will return additional information about an error.
(the name of your dev controller is usually your app name suffixed with _dev.php so front_dev.php assumes your app name is front, which is default btw)

PHP - product comparison table displaying only one column

I am trying to compare products and display results in a table. I have a form page and a TABLE page, the problem is that when i select in the FORM page from the two drop-downs the same product(value) it will only display in the table one column and returns an multidimensional array containing one array not two arrays identical. When i select two different values from the from and submit, both selections are displayed. How can I avoid having one empty column if the user select the same product /ID ?
I was thinking maybe load the second drop down and subtracting from the list the value of the first drop down selection? I am not sure how to do it Or maybe there is an easier way like a form validation. Can someone show me how? Thanks
FORM.html
<?php
$products_dropdown = "select * from product_dp" ;
$statement = $dbh->prepare($products_dropdown);
$statement->execute();
$result_dp = $statement->fetchAll();?>
<form action="table.html" method="post">
<fieldset class="custimg">
<legend>Product Comparison</legend>
<div class="row">
<div class="large-block-grid-4"><br /></div>
<div class="large-block-grid-4">
<select name="id1" id="id1" class="small button secondary dropdown radius">`
<?php foreach ($result_dp as $row){
echo "<option value='".$row['id']."'>".$row['sku']."</option>";}?>
</select>
</div>
<div class="large-block-grid-4">
<select name="id2" id="id2" class="small button secondary dropdown radius">
<?php foreach ($result_dp as $row){
echo "<option value='".$row['id']."'>".$row['sku']."</option>"; }?>
</select>
<input type="submit" value="Compare" class="tiny button secondary" />
</div>
</div>
Table.html
$id1 = $_POST[id1];
$id2 = $_POST[id2];
$statement = $dbh->prepare("select * from products_specs where id IN ($id1,$id2)");
$statement->execute(array(':id1' => $id1, ':id2'=> $id2));
$statement->setFetchMode(PDO::FETCH_ASSOC);
$subrows = $statement->fetchAll();
print_r($subrows);
$yes = '<img src="images/icons/yes.png" width="16" height="16" />';
$no = '<img src="images/icons/no.png" width="16" height="16" />';?>
<table >
<thead>
<tr>
<th width="100"></th>
<th width="275"><?php echo $subrows[0][image]; ?></th>
<th width="275"><?php echo $subrows[1][image]; ?></th>
</tr>
<tr text-align="center">
<th width="100"></th>
<th class="centered-cell1"><font color="#990000"><?php echo "ID"." ".$subrows[0][id]; ?></th>
<th class="centered-cell1"><font color="#990000"><?php echo "ID"." ".$subrows[1][id]; ?></th>
</tr>
</thead>
<tbody>
<tr>
<td > Capacity </td>
<td align="center"><?php echo $subrows[0][capacity]; ?> </td>
<td align="center"><?php echo $subrows[1][capacity]; ?> </td>
</tr>
<tr>
<td > Memory </td>
<td align="center"><?php echo $subrows[0][mem]; ?> </td>
<td align="center"><?php echo $subrows[1][mem]; ?> </td>
</tr>
ect....
Very simple solution. After executing query use code:
if (!isset($subrows[1]))
$subrows[1] = $subrows[0];
Let users compare a product with itself if they want it.

get the value of a checkbox then pass it to a link to edit a page

I have been working on this script that should get the value of an id field in a database through a checkbox that will be used by a link to edit a page. I know there are topics relating to this but non deals with using the value of the checkbox in a link. The checkbox is actually getting the value of the id from the database i know this because i used inspect element in firefox to view the value of the checkbox. The issue I'm having is using this value in a link to edit a page. Any help will be appreciated. My script is displayed below.
<td width="341" height="73"><h1><strong><span class="style2">EVENTS </span></strong></h1></td>
<td width="59" align="right"><div align="right"><strong>New</strong></div></td>
<td width="66" align="right"><div align="right"><strong><a href="edit_event.php?id=<?php
if (isset ($chek)) {
echo urlencode($chek);
}
?>"/>Edit</a></strong></div></td>
<td width="82" align="right"><div align="right"><strong>Archive</strong></div></td>
<td width="79" align="right"><div align="right"><strong>Unarchive</strong></div></td>
<td width="70" align="right"><div align="right"><strong>Delete</strong></div></td>
<td width="71" align="right"><div align="right"><strong>Exit</strong></div></td>
</tr>
</table>
<p> </p>
<table width="786" border="1">
<tr valign="top">
<th width="46">Event Title</th>
<th width="27"><input type="checkbox" name="checkbox1" value="checkbox" /></th>
<th width="37">Start Date</th>
<th width="36">End Date</th>
<th width="43">Start Time</th>
<th width="38">End Time</th>
<th width="43">Venue</th>
<th width="45">Event Type</th>
<th width="94">Event Description</th>
<th width="152">Event Program</th>
<th width="79">Reminder Date</th>
<th width="70">Reminder Time</th>
</tr>
<?php foreach($events as $event): ?>
<tr valign="top">
<td><?php echo $event->event_title; ?></td>
<td> <form id="form1" name="form1" method="post" action="">
<?php echo "<input type=\"checkbox\" name=\"chek[]\" value= $event->event_id id=\"chek\"/>"; ?>
</form>
</td>
<td><?php echo $event->start_date; ?></td>
<td><?php echo $event->end_date; ?></td>
<td><?php echo $event->start_time; ?></td>
<td><?php echo $event->end_time; ?></td>
<td><?php echo $event->venue; ?></td>
<td><?php echo $event->event_type; ?></td>
<td><?php echo $event->event_description; ?></td>
<td><?php echo $event->event_program; ?></td>
<td><?php echo $event->reminder_date; ?></td>
<td><?php echo $event->reminder_time; ?></td>
</tr>
<?php endforeach; ?>
<?php
$check = $_POST['chek'];
if(empty($check)){
$$check="";
}else{
$N = count($check);
for($i=0; $i < $N; $i++){
$chek =($check[$i]);
}
}
?>
I don't know if my question is understood, what i meant is that I want the value of my check box to display after (http://localhost/emgt/admin/edit_event.php?id=) id so i can edit that particular row.
You can check with the below link. It may be helpful for you.
As far I see you need to add class, and id to your checkbox and use a jquery/javascript function to call the value in your href.
Pass checkbox value to Edit (using href)
Hope it would be of some help to you.
I'm sorry, i found your code to be a little unclear. If you mean calling a url with the checkbox value as a parameter you can do so by adding an "id" property to the checkbox element, and then calling the page like:
var chk = document.getElementById("checkbox_id");
var url = "http://localhost/emgt/admin/edit_event.php?id=" + chk.value;
location.href = url;

Categories