What result or output do you get on the page when you submit the form? It is highly likely that the use of the short opening php tag <? is not enabled and the php code isnât being executed. If you do a âview sourceâ of the page in your browser you will see the raw php code.
Do you have phpâs error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system so that php will help you by reporting and displaying all the errors it detects?
You should be using a post method form, since you are performing an action on the page, e.g. inserting data in a database table.
You should use ârequireâ for things your php code must have for it to work.
In html5, an empty action=ââ attribute is not valid. To cause a form to submit to the same page it is on, leave out the entire action attributed.
The post method form processing code should -
Detect if a post method form was submitted.
Trim (mainly so that you can detect if all white-space characters were entered), then validate all inputs before using them, storing user/validation errors in an array using the field name as the main array index.
After the end of the validation logic, of there are no errors (the array holding the user/validation errors is empty), use the submitted data.
You should be using a prepared query to prevent any sql special characters in a value from being able to break the sql query syntax, which is how sql injection is accomplished.
You should always list out the columns for an insert query. This helps make your code self-documenting and insures that if the order of the columns in the table is altered, that the query will continue to work correctly.
You should NOT store plain-text passwords. Use phpâs password_hash() and password_verify().
Your database design must enforce uniqueness (it is the last step in the process.) Any column(s) that must be unique, must be defined as a unique index. You would than test in the error handling for this insert query if a duplicate index error (number) occurred. If the error number is for a duplicate index error, you would setup a message (add it to the array of user/validation errors) letting the user know what was wrong with the data that they submitted.
Because you donât have any conditional logic to detect if the form has been submitted (see item #1 in the list I posted), it runs when the page is first requested, when there is no form data.
I understand the logic, since I wrote the code, I had to send data to the server, but this is not there, now I want to understand why this does not happen, I do not know another form of recording.
Is this entry needed to remove the spaces in $_POST[ânameâ]? since with my entry the values \u200b\u200bget into the database, now I want to figure out how to remove the spaces.
If the problem was the missing quotes around name, wouldnât PHP produce an âundefined constantâ error? OP, which of those lines of code is line 4?
Iâll post my answer in the form of a question (Jeopardy theme can be heard in the background.) Why have you put the conditional logic that detects if the submit button isset() (which is not what was suggested to use) AFTER the point where you have referenced elements of the $_POST data, where those unconditional references will produce undefined index errors when the page is first requested? Wouldnât you need to put all the code that references the $_POST data INSIDE the conditional branch that has detected if a post method form has been submitted?
You were also told in the 1st reply in the thread that you need to use a prepared query, and why to do so (item #4 in the list I posted) and to not store plain-text passwords, and what to use instead (item #6 in the list I posted.)
There are two ways of putting an associative index array element inside a double-quoted string -
Leave the quotes off of the associative index name (what the OP is doing.)
Put {} around the variable reference, e.g. {$_POST["name"]} or {$_POST['name']} (both work.)
And hereâs a fun fact - when you put a php variable - scalar, array element, object->method() (yes you can put an object method/function reference inside of a string), or object->property inside a double-quoted string, when php parses that string it produces the EXACT same tokenized byte-code as if you had used concatenation to build the string.