What's new

Phc robot patulong sa code

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
Warning: Undefined variable $post_row in C:\xampp\htdocs\Innerjoin\user\posting.php on line 62

Warning
: Trying to access array offset on value of type null in C:\xampp\htdocs\Innerjoin\user\posting.php on line 62


bakit kaya ganito error ilan araw lang di ko nabuksan.. siguro sa hours, days po ang error nya


$post_query = mysqli_query($con, "SELECT *,UNIX_TIMESTAMP() - date_created as TimeSpent FROM post left join registration on registration.user_id = post.user_id where comment_id = '$id_comment' order by comment_id DESC limit 1 ") or die(mysqli_error($con));
// loop
while ($content_row = mysqli_fetch_array($post_query)){
$id = $content_row['comment_id']; //get the comment_id
$uid = $content_row['user_id']; //get the user_id
$postedby = $content_row['username']; //get the username
?> <div class="container col-md-6 bg-body-tertiary border rounded-3 mb-2 p-3">
<h5>Title: &nbsp;&nbsp;<?php echo $content_row['title']; ?></h5>
</div>
<!-- body of posted -->
<div class="container col-md-6 bg-body-tertiary border rounded-3">
<p>Posted by: <a href="#" style= "margin-left:10px; text-decoration:none;"> <?php echo $postedby; ?></a>
<!-- time interval --><br>
<?php
$days = floor($content_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $content_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $post_row['date_created']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';


?>
 
The error you're getting is related to an undefined variable called $post_row. In your code, you are trying to access an array offset using $post_row, but it is not defined anywhere in the code you provided.

Based on your code, it seems like you may have made a mistake, and instead of using $post_row, you should be using $content_row to access the 'date_created' value.

To fix this issue, you can replace the line:

PHP:
echo date('F d, Y - H:i:sa', $post_row['date_created']);

with:

PHP:
echo date('F d, Y - H:i:sa', $content_row['date_created']);

This will use the correct variable $content_row to access the 'date_created' value.

Additionally, it's worth mentioning that you should sanitize user input before using it in your SQL query to prevent SQL injection attacks. You can use prepared statements or mysqli_real_escape_string() function to sanitize the input.

Here's an example of how you can sanitize the $id_comment variable:

PHP:
$id_comment = mysqli_real_escape_string($con, $id_comment);

By doing this, you will ensure that the user input is safe to use in your SQL query.
 

Similar threads

Back
Top