0

need help with php form

Hey guys, I need to do this: a form which lets me introduce data about an animal, and when I press submit, the animal and its values must be written in the page, and everytime I do this the new animal must be written next to the others. I know how to get the values and write in the page, but the data printed gets replaced everytime I press submit. I need to be able to store all the animals in the page, next to each other. Any help would be appreciated. Thanks!!

10th May 2017, 12:37 AM
ilearndev
11 Answers
+ 3
If you use only php and not a database or a file to store the data, everytime you submit the previous data will be lost.
10th May 2017, 1:02 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 3
If you are using php and do not use a database or a file to store the data, everytime you submit the page will refresh and you will lose the previous information.
10th May 2017, 1:02 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
If you don't need the data for a long long time(forever), instead of a database you could use cookies.
10th May 2017, 1:15 AM
CHMD
CHMD - avatar
+ 1
One solution would be to use a database. You had to make a script that would receive the data of an animal and insert it in the database. After that it would update the page with the values in the database. It would be a script that submits to itself. This solution is if you are trying to have the values stored for a long periode. If not just use javaScript and listen to the submit event then create an element dinamically and add it to the page.
10th May 2017, 12:56 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
For cookies : Upon submission and after checking that all is good , the syntax to create a cookie is: setCookie("name", $value, time() + 7200, "/"); 1st param is the name of the cookie second is the value that you want to store. the third, time() + 7200, is the expiration date is in seconds basically this means two hours from the time of submission. the fourth param means that the cookie can be accessed from any part of the domain You can then access your cookie with the superglobal $_COOKIE["cookieName"];
10th May 2017, 1:33 AM
CHMD
CHMD - avatar
+ 1
@Bogdan The session variables would be clear whenever the visitor close the webpage. However you can override it, by changung a variable, session.cookie_lifetime (default=0) in php.ini You can use php command to do it, before session start ini_set('session.cookie_lifetime', 100*24*3600); // 100day expired session_start();
10th May 2017, 2:30 AM
CalviŐ˛
CalviŐ˛ - avatar
0
This is a homework..the teacher says we can only touch the php file. is there any way to do it only using php ?
10th May 2017, 1:00 AM
ilearndev
0
Ok, I understand..thanks a lot :)
10th May 2017, 1:03 AM
ilearndev
0
it's session_start() function? how to inplement it?
10th May 2017, 1:22 AM
ilearndev
0
you can use a hidden input in the form tag if you don't use a data base 😉
10th May 2017, 1:23 AM
Elghozi Nasreddine
Elghozi Nasreddine - avatar
0
I've tried with session function....and the problem is every time I reload the page..the code is executed. They ask me also to drag and delete an item ( drag to the trush icon)... It can be done if session is used? I use a multidimentional array to store all the items created...
10th May 2017, 2:57 AM
ilearndev