I need to save the data within these page elements into a database - they will be dynamically created by the user, but always in a similar format
The HTML appears:
<div><p>1</p>
<div><p>Broccoli</p></div>
<div><p>Carrot</p></div>
</div>
<div><p>2</p>
<div><p>Chicken</p></div>
<div><p>Beef</p></div>
<div><p>Lamb</p></div>
</div>
values needed from this:
"1:Broccoli", "1:Carrot", "2:Chicken", "2:Beef", "2:Lamb"
(happy to add classes/IDs to any divs to extract the required values)
What should happen:
On click of a save button, data is scraped into an array (via
Jquery?)
Array is sent to PHP file and inserted into the database
Any help on this would be great, thanks
you should save this data to the database as the user is creating it. not try to scrape your own page afterwards. This is going o save you a lot of time and make your script run faster.
Once you've done that, you can use serialize() to convert your array into a string that you can store in a database, and then turn the string back into an array with unserialize()
Related
Sorry very new to PHP and MySQL. I'm pretty close to having what I need. I created a database that hold values as shown here:
I was able to find some things online to create a form and initially get the data into the database
What I would like to do is have another page to load values for a specific customer by searching for their uniqueid. So have a input box where you input the uniqueid then the current values for that customer get loaded into a form just like the "Customer Creation Form". Then be able to update the loaded values in the the form and save it back. The enddate is probably the field that would be updated the most.
You could use Ajax requests and PHP to update the form live (or update once the user has entered the UniqueId)
https://www.w3schools.com/php/php_ajax_php.asp
To return multiple values grabbed from the database, use php to create an array return it as a json file.
https://www.w3schools.com/js/js_json_intro.asp
https://www.w3schools.com/js/js_json_arrays.asp
https://www.w3schools.com/js/js_json_php.asp
I'm having two forms in a row. I would like to make the user fill in the first form, and after they submit the from, I'm going to provide another form to let the user fill in their names.
Well, right now I have couple ideas how to do this, but just out of curiosity. Is there any other way that I can do this?
The first idea is to post the first form, and use json_encode() to convert the array to a string, then pass it to the 2nd form as a hidden input.
The second idea is to put all the data from the 1st from in the url, so the 2nd form can access these data by using the get method. However, if the data is too large, this will not work.
I'm looking for a way that I can post all data from both 1st form and 2nd form at once, then save them in the database. I don't want to divide the insert data process into 2 steps, since all these data are in the same table.
I am trying to pass the values of variables from one php page to another php page. Is it possible to include the previous php page in the next php page using include statement and use those variables and values rather than using $_SESSION['variable']="value".
If not, is there any other way to pass the values? Thanks in advance!
No. You'll run the code in the included file again, from scratch. Any data produced based on user input will have been lost.
If not, is there any other way to pass the values?
Passing the entire value to the browser and having it send the entire value back to the new script. (via form data, query strings in links, cookies, etc).
I am trying to create a script where a user can post something they want to sell and then I am using while loop in php to display the information from the database. Other users can click on the contact button and send an email to them. I was told that if I use 'session', the same email id will be stored for every listing. So I am wondering if I can use the hidden field and if so, how do I assign that php variable value to the html hidden field?
You can't use hidden fields for this. You need to store persistent data on the server. Store the email address with the rest of the information in the database. (You'll probably want a separate user table and associate the For Sale item with a user using a foreign key).
I have a dynamic html table( rows are added dynamically using java script) and I want to pass whole table to a php script as an array.Is there a way to insert the table data to an array?
I have tried using phpTableExtractor but it dosen't extract dynamically added rows.
I don't see any other reliable solution but creating a HTML form along with the table and have the user click a submit button to save the table. Then you can read all content from $_POST and store it in a database.
Another solution would be to use AJAX requests to store the table content every time the focus changes or something like that. Will make your page dependent on JavaScript though.
What if you fill a JS array at the same time you create the table?
You will use the html just for display but behind you have the data you send to php.
the application simply is
dynamic page generate html code with some data within table cells by receiving parameters
i could get these pure data by jquery
but i find trouble sending it by ajax to another page(the basic page)
to display it in another format
You could try to serialize the table into a json and pass it to the next page where you could recreate the table based on the json. Just a quick idea