php: How to create a file containing variable definitions - php

So first I want to say that I'm pretty new to php & javascript. But anyways, I want to make something like a User Interface (1) where you can write sth into certain fields which will create a string for every field and save it into a file on the server so you can get the values the fields should have from other devices.
This is a little graphic to show you what I want to make:
So I'm wondering if anybody knows if it's possible and how to create the file/load the values from it.

I think what you might want is a database, that way one php function can write those values to a db and then another can retrieve those values whenever.

If u r using mysql then ...
Create a php script that passes the parameter to database using mysqli_query function (that is saving data in database) and after that the website script can retrieve data from the database. .

Related

Looping mysql Table Values on a CSS Table

I have a table with date/time, temperature and humidity data stored on a mysql database.
I have a ugly looking but working HTML one so I made a new CSS table using templates and wanted to use the looping in PHP (as in the HTML) to fetch data to the table using the table designers format. (Some datas are manually in as in the sample table photo)
I want to automate that but my PHP script has a problem and does not load the page. shows error.
Im very new to LAMP environment actually and unsure if I can use class variables inside the PHP script without changing anything.
My table looks like this without the python script: https://imgur.com/a/WmpHzMZ
The code is here: https://codeshare.io/amvPYw
(I cannot add code here, it says bad formatting everytime)
Html element tags are close like </tr>. See your end line in while loop.

How to autoload data from a database in laravel PHP

I have a question on how to achieve something from a development standpoint in Laravel. I am looking for ways to use autoload to return data from a database by just supplying a few character entry. For example, if I need to search for the word 'Johnson' which is already stored in a table in the database, supplying the word: 'Joh' in the search bar should bring up Johnson and other names like Johnson. I am very new to PHP and laravel, does anyone have any suggestions?
You are going to have to use Ajax and php to do this.
Basically the logistics will be as such:
a key is typed into an input which will load a javascript function that does a post to a php file. That php file will do a query for "Joh%". All records will come back matching Joh%. Print them out with php and it will be delivered back to the javascript function which called the php file in the first place. Now that javascript function will have to manage adding and subtracting entries from the dropdown on the input box you are typing in.
The question your asking is basically a lot of code and you should take it step by step. First start by getting a php query to work where you get records matching "Jon%", then continue on to another step.

Dynamic generation of <option> list without separate php file

I need to create a specific <option> list on a form, depending on which option is selected by the user on the previuos <select> list. In this case, as part of a school ERP, when user selects course the system should load on the next field only the subjects related to this course.
This can be done by ajax, using the 'change' method, posting on real-time course ID, and giving back as the result of the query, the list of related subjects wich is loaded on its <select> list.
Is making this by having a separate file instead of trying another options the best practice to solve this cases? I mean, if the best way to do this is by having an specific file for every list that must be dinamically generated, then I'll make it this way, but I feel that having a php file for every single dynamic list that should be generated on real-time maybe is not the most efficient way to do this (got many form fields that should behave this way).
One PHP file will do.
Use this tutorial to learn about URL parameters:
http://html.net/tutorials/php/lesson10.php
Combine with this tutorial on how to retrieve data from a database:
http://html.net/tutorials/php/lesson20.php
The idea here is, using AJAX, instead of fetching your list like this:
http://example.com/list/thing1.php, http://example.com/list/thing2.php
You use a single PHP file, like this:
http://example.com/list.php?foo=thing1, http://example.com/list.php?foo=thing2
So instead of having a php file for every single dynamic list you can have one file that loads and format the specific data you need dynamically.

Storing webforms data within PHP pages

I was reading a book about PHP and I wanted to know how can you store data(of web forms) in PHP pages? I know the process of creating a php file and recieving the data using $_POST(or any other way like this). But those values would be overwritten when you submit the webform again.
Without using the database or emailing the data, is there a way to store multiple webform's data in PHP?
If you want to store submissions from multiple sessions (or clients), you'd have to use some sort of database.
It could be an RDBMS like MySQL, and it could be a simple file: http://www.dummies.com/how-to/content/storing-data-with-php-flat-file-or-database.html
The easiest way is using a database, since MySQL is working very well together with php, often a php server includes MySQL and phpmyadmin which makes it easier to create and edit the database, then you just need a php script you include at the top op your page to set up the MySQL connection.
If this didn't convince you to use a database you could use this code as well:
$filename = "<your filename here>";
$content = "username=".$_POST['username'].":password=".$_POST['password']."{etc etc etc}."\n";
file_put_contents($filename,$content,FILE_APPEND);
The code above adds a row with the content to your file with the delimiter : (colon).
Make sure the filename already exitst somthing like: data.txt

HTML Table row edit/Delete

I have an HTML table with contents, I would like to have an feature of Edit/Delete to that table. How do I do it with PHP?
I actually think that this sounds more like a job for JavaScript, which can edit/remove rows on-the-fly and with much less code. (Implement some AJAX too, and you can edit/remove rows in database too).
But if you insist on using PHP, you might just want to add some GET parameters to the Edit/Delete links that would delete or edit those rows.
Well, there is a pure PHP way to do it, and then there is a combination of Javascript and PHP. You must use PHP one way or another if you want your changes to the database to be permanent as that is your gateway to communicating with the database (as far as I know you cannot do that with Javascript as that is client-based and runs entirely in your web browser).
If using just PHP, you must generate HTML documents for each change. E.g., you click on one cell in the table and that gets you to a new HTML page where the field is editable through an input element; or you can list all fields at once for that row and edit them all at the same time. The fields are then posted in a form to a PHP page which will take the new values and update the database (or insert new values or however you wish it to behave). Here's a tutorial for how to do this:
http://www.freewebmasterhelp.com/tutorials/phpmysql/1
You can also mix in some Javascript which allows a more interactive interface to modifying the values in a cell. However, this obviously requires more code and may be overkill for what you're trying to do. Nonetheless, here is a link which demonstrates just that and also shows the code:
http://www.java2s.com/Code/JavaScript/GUI-Components/Editabletablecell.htm
Hope this is what you're looking for.
EDIT:
Forgot that you also wished to delete content in the table. That is also explained in the first link.
If you intend to work with databases, and it seems like you have little understanding of how they work, pick up a good book like: SQL - The Complete Reference. When you have enough knowledge of SQL, look at PHP's PDO extension: http://php.net/manual/en/book.pdo.php

Categories