I am using webhosting000 for a sixth-form computing unit. This is my first time using PHP so please forgive any beginner errors, when I try to append $userInput into UserNotes.txt I am receiving an error message.
Notice: Undefined index: userMessage in /storage/ssd3/381/15908381/public_html/index.php on line 34
I have read through the PHP website and W3schools on the use of \n and \r\n to append to a new line but I cant find the source of the problem within my code. What do I need to do to solve this error and be able to save the user's message within the text file on a new line?
<!DOCTYPE html>
<html>
<body>
<h1>This Is a Website</h1>
<?php
echo "I wrote this using php";
?>
<br>
<h2>Your IP Address:</h2>
<?php
$user_IP = $_SERVER['REMOTE_ADDR'];
echo $user_IP;
?>
<br>
<h2>Your browser Information:</h2>
<?php
$browserInfo = $_SERVER['HTTP_USER_AGENT'];
echo $browserInfo;
?>
<br>
<h2>Your Screen Information</h2>
<script>
var screenWidth = window.screen.width;
var screenHeight = window.screen.height;
document.write("Screen width: " + screenWidth + "px" + "<br />");
document.write("Screen height: " + screenHeight + "px" + "<br />");
</script>
<br>
<h2>Send me a message!</h2>
<?php
$file="userNotes.txt";
if(isset($_POST["submitButton"]))
{
$userInput = $_POST["userMessage\r\n"];
file_put_contents($file, $userInput, FILE_APPEND | LOCK_EX);
}
?>
<form action="" method="post">
<input type="text" name="userMessage">
<input type="submit" value="send" name="submitButton">
</form>
</body>
</html>
"You are using "userMessage\r\n" as the field name. If you want to add a new line after the field, use $_POST["userMessage"] ."\r\n" ??� Nigel Ren 1 hour ago"
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.