What's new

Bakit kaya di sya nalabas

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
bakit kaya po walang display sa screen ko itong <?php echo $posted by; ?>

ito po code ko

<?php
$slq = mysqli_query($con, "SELECT * ,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN registration on registration.user_id = post.user_id ORDER BY comment_id DESC " ) or die (mysqli_error());
while($post_row = mysqli_fetch_array($slq)){
$id = $post_row['comment_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['username'];
?>
<a style="text-decoration:none; float:left;" href="deletepost.php<?php echo '?id='.$id; ?>">
<h3>Posted by: <a href="#"> <?php echo $posted_by; ?></a>
<br><?php echo $post_row['comment']; }?></h3>
 
There could be a few reasons why there is no display on the screen for the <?php echo $posted_by; ?> code. Here are a few things you can check:

1. Database Connection: Make sure you have established a successful connection to your database using mysqli_connect() function before executing the query.

2. Variable Assignment: Check if the $con variable is properly assigned and contains the correct database connection details.

3. SQL Query: Verify that the SQL query is correct and returns the expected results. You can test the query directly in your database management tool (e.g., PhpMyAdmin) to ensure it fetches the desired data.

4. Error Handling: Wrap the database query in an if statement to check for any errors. For example:
PHP:
if (!$slq) {
    die('Error: ' . mysqli_error($con));
}

5. Database Field Names: Ensure that the field names used in the query match the actual column names in your database table. Double-check the column names comment_id, user_id, username, comment, and date_created used in the query and make sure they are spelled correctly and case-sensitive.

6. Loop Structure: Confirm that the while loop is correctly structured and that it iterates through each row returned by the query. Verify that the <a> tag and the <h3> tag are properly nested and closed.

7. Data Availability: Check if there is any data available for the post and registration tables. Make sure there are matching records in both tables for the join to work correctly.

By carefully reviewing and troubleshooting these areas, you should be able to identify and resolve the issue causing the lack of display on your screen.
 
There could be a few reasons why there is no display on the screen for the <?php echo $posted_by; ?> code. Here are a few things you can check:

1. Database Connection: Make sure you have established a successful connection to your database using mysqli_connect() function before executing the query.

2. Variable Assignment: Check if the $con variable is properly assigned and contains the correct database connection details.

3. SQL Query: Verify that the SQL query is correct and returns the expected results. You can test the query directly in your database management tool (e.g., PhpMyAdmin) to ensure it fetches the desired data.

4. Error Handling: Wrap the database query in an if statement to check for any errors. For example:
PHP:
if (!$slq) {
    die('Error: ' . mysqli_error($con));
}

5. Database Field Names: Ensure that the field names used in the query match the actual column names in your database table. Double-check the column names comment_id, user_id, username, comment, and date_created used in the query and make sure they are spelled correctly and case-sensitive.

6. Loop Structure: Confirm that the while loop is correctly structured and that it iterates through each row returned by the query. Verify that the <a> tag and the <h3> tag are properly nested and closed.

7. Data Availability: Check if there is any data available for the post and registration tables. Make sure there are matching records in both tables for the join to work correctly.

By carefully reviewing and troubleshooting these areas, you should be able to identify and resolve the issue causing the lack of display on your screen.
ito po

Warning: Undefined variable $user_id in C:\xampp\htdocs\Innerjoin\user\comment.php on line 34

<?php
if (isset($_POST['post'])){
$page_content = $_POST ['post_content'];

mysqli_query($con,"INSERT INTO post (comment,date_created,user_id) values ('$page_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());

}
?>
 
ito po

Warning: Undefined variable $user_id in C:\xampp\htdocs\Innerjoin\user\comment.php on line 34

<?php
if (isset($_POST['post'])){
$page_content = $_POST ['post_content'];

mysqli_query($con,"INSERT INTO post (comment,date_created,user_id) values ('$page_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());

}
?>
The warning message indicates that the variable $user_id is not defined in your code. To resolve this issue, you need to ensure that the variable is properly assigned a value before using it in the SQL query.

Here are a few steps you can follow:

1. Check the variable assignment: Look for the part of your code where you set the value of $user_id. It seems that you haven't included that part in the code you provided. Make sure to assign a value to $user_id before using it in the SQL query.

2. Determine the source of $user_id: You need to identify where the $user_id value should come from. It could be from a form input, session variable, or any other source. Ensure that you are correctly retrieving the user ID and assigning it to the $user_id variable.

3. Validate the $user_id value: Before using it in the SQL query, validate the value of $user_id to ensure it is not empty or contains any malicious data. You can use functions like isset() or empty() to check if the variable has a value.

Once the variable $user_id is properly assigned and contains a valid value, the warning message should no longer appear, and the SQL query should execute successfully.
 

Similar threads

Back
Top