What's new

Patulong po

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
patulong ulit po


Warning: Undefined array key "page_content" in C:\xampp\htdocs\Innerjoin\user\post.php on line 43

Warning
: Undefined variable $post_content in C:\xampp\htdocs\Innerjoin\user\post.php on line 45

</div>
<label class="fw-bold mb-2" for="w3review">Content:</label>
<textarea name="post_content" class="form-control" id="post" rows="10" cols="50" placeholder="Your Content....."></textarea>
<div class="form-group mb-5 mt-2">
<button name="post">&nbsp;POST</button>
<!-- <input class="col-md-3" type="submit" value="Post" style="background:#42A5F5";> -->
</div>

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

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

}
?>
 
The error you're encountering is due to undefined array keys and variables in your code. Let's go through the issues and provide the necessary corrections.

First, the error message "Undefined array key 'page_content'." This error occurs because you're trying to access the 'page_content' key in the $_POST array, but it hasn't been defined in your HTML form. To resolve this, you need to add an input field with the name attribute "page_content" in your HTML form. Here's an example:

HTML:
<input type="text" name="page_content" class="form-control" placeholder="Page Content">

Next, the error message "Undefined variable $post_content." This error occurs because you're trying to insert the value of the undefined variable $post_content into your SQL query. To fix this, you need to change "$post_content" in your SQL query to "$page_content" since you've assigned the value of $_POST['page_content'] to $page_content. Here's the corrected code:

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

Additionally, please ensure that you have established a connection to your database using the $con variable before executing the query.

Remember to validate and sanitize user input before inserting it into your database to prevent SQL injection attacks.
 
The error you're encountering is due to undefined array keys and variables in your code. Let's go through the issues and provide the necessary corrections.

First, the error message "Undefined array key 'page_content'." This error occurs because you're trying to access the 'page_content' key in the $_POST array, but it hasn't been defined in your HTML form. To resolve this, you need to add an input field with the name attribute "page_content" in your HTML form. Here's an example:

HTML:
<input type="text" name="page_content" class="form-control" placeholder="Page Content">

Next, the error message "Undefined variable $post_content." This error occurs because you're trying to insert the value of the undefined variable $post_content into your SQL query. To fix this, you need to change "$post_content" in your SQL query to "$page_content" since you've assigned the value of $_POST['page_content'] to $page_content. Here's the corrected code:

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

Additionally, please ensure that you have established a connection to your database using the $con variable before executing the query.

Remember to validate and sanitize user input before inserting it into your database to prevent SQL injection attacks.
ganito po error

Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSER INTO post (content,date_created,user_id) values ('sdsds','1689695282','3')' at line 1 in C:\xampp\htdocs\Innerjoin\user\post.php:45 Stack trace: #0 C:\xampp\htdocs\Innerjoin\user\post.php(45): mysqli_query(Object(mysqli), 'INSER INTO post...') #1 {main} thrown in C:\xampp\htdocs\Innerjoin\user\post.php on line 45
 
ganito po error

Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSER INTO post (content,date_created,user_id) values ('sdsds','1689695282','3')' at line 1 in C:\xampp\htdocs\Innerjoin\user\post.php:45 Stack trace: #0 C:\xampp\htdocs\Innerjoin\user\post.php(45): mysqli_query(Object(mysqli), 'INSER INTO post...') #1 {main} thrown in C:\xampp\htdocs\Innerjoin\user\post.php on line 45
The error is caused by a syntax error in your SQL query. The correct syntax is "INSERT" instead of "INSER". Here's the corrected code:

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

Make sure to replace the incorrect "INSER" with "INSERT" in your code.

Additionally, ensure that you have established a connection to your database using the $con variable before executing the query.
 

Similar threads

Back
Top