Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error inside username and email input #2

Open
josepedrolorenzini opened this issue Jun 27, 2022 · 2 comments
Open

Error inside username and email input #2

josepedrolorenzini opened this issue Jun 27, 2022 · 2 comments

Comments

@josepedrolorenzini
Copy link

hello Shaun
i have got this error, i have copied your code at the end and i got the same error, do u think must be my php version??
this are the inputs::

this are the errors:


Notice: Undefined index: username in C:\xampp\htdocs\marble\php\thenetninja\objects\formproject\index.php on line 29


Notice: Undefined index: email in C:\xampp\htdocs\marble\php\thenetninja\objects\formproject\index.php on line 34

please let me know
and thanks for your course i have learn a lot with the net ninja
regards
jp

@karhong-sam
Copy link

karhong-sam commented Jan 31, 2023

Hi @josepedrolorenzini,

I saw the solutions from the comments, hope it helps.

Replace

<input type="text" name="email" value="<?php echo htmlspecialchars($_POST['email']) ?? '' ?>">

To

<input type="text" name="username" value=<?php echo !empty($_POST['username']) ? htmlspecialchars($_POST['username']) : ' ' ?>>

"The error happens because the htmlspecialchars() function tries to run with $_POST data, which is null, since we havent submitted the form yet." -- quotes from Max Bub from Object Oriented PHP #14 - Validation Class (part 3)

@josepedrolorenzini
Copy link
Author

thanks guys!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants