How to add only one data in database table in laravel - php

I am creating a site and i am making a general option page for the site that include the site name, logo, social links so that i can manage them dynamically from one place without changing the links and text in all pages where i called them.
What I want is that the table i created in database, i want to have only one row in it. If someone try to add other row of data it should not be added because i have to call only one data for the site.
I hope the query is clear to all.
Thanks for your support. Help me if u can. please :)

By,
if someone try to add other row of data it should not be added
what do you mean? Are you trying to avoid unauthorized access? If yes, then you need to implement roles https://laracasts.com/discuss/channels/general-discussion/roles-and-permissions-in-laravel-5
To manage your site information, I'm sure you set a form that will be used to update the site info. And from the look of things you will only be updating that row when you hit save or update button. I don't think you will be doing full CRUD here just updating so there'll be no chance of inserting a new row of data in the db.
So three things:
you want to create a migration, seed the table with the site details accordingly. run the migration
you want to make sure the user trying to access this route is authorized to do so
you want to pre populate the site info in the form fields when the edit site info page loads and you want to save the form when the authorized user changes any of the site info
This way, there'll be no question of stopping further insertions into the db.

Related

Added something to the database but not reflecting in wordpress page

there is this wordpress plugin, the main functions of that plugin is to take data from the user and write that data to the database, it also Update data and Delete data, then display the changes to the page that the plugin provides.
Now, I want to add thousands of items, but I cannot manually add each items using the plug-ins interface because that would take so long, so what I did is I head over to phpmyadmin locate the tables of the plug-in and I use sql Insert to add data to the database, after trial and error, I SUCCESSFULLY inserted all of the data in all of the tables that is relevant to the plug-in, no errors!.. I analyzed it carefully. but when I head over to the page, and to the live site, the items that I inserted is not showing up. not even one. the items that is only showing is the items that I added using the plug-ins interface, what should I do?
Good job by the way, but make sure that
1. You're inserting data to the correct schematic & table.
2. You didn't insert a null or invalid data (like floats in int data type)
3. try refreshing the page if that's a cache problem, clear the cache and try again

How to create a form for updating a record using chronoforms?

I'm using chronoforms 5, made a form for creating a record. It works all fine.
But my problem is I need a form for edit the record. I've no idea how to load & show the record data. Anyone has ideas?
You have to be able to identify the record you want to edit. Usually this is by the Record ID, the User ID, or possibly the User email if that is unique. Then you can make a copy of your entry form, rename it, and add a DB Read action at the top of the On Load event in the Setup tab - if you are using the Simple Wizard then you have to switch the form to Advanced mode in the General tab to do this.
Edit the DB Read action to link to the table and set the Conditions box to load the record you want to edit - there is a FAQ about doing that.
You should be using ChronoConnection to list the records. The user selects a record which then displays the form to edit it.

Database Concurrency Problems

I'm currently developing a database/website server interface to facilitate inputting data for a data collection project. There are two types of additions being made to the database: A and B here. Some of the tables in the database that handle these entries are as follows:
dcs_projectname_a
dcs_projectname_b
Each of these have tables for all the required input fields in addition to things like creator, timestamp, etc.
The pages on the website facilitate three different options: add, view, and edit. Each page for each type of entry performs the respective function. That is, the add page adds, view page views, etc.
I am just about done; however, there is a major challenge I haven't really confronted yet: concurrency. There will be multiple users adding content to the database at the same time. Each entry is given its own specific id and there CANNOT be any duplicate id's. That is, the first a entry is A000001, the next is A000002, and so on.
On the add and edit pages, there is a disabled field for the user to view the id for other uses when physically documenting entries.
What I need to figure out is how to implement concurrency management so that when users are concurrently adding a's that they will not be under the same id and row.
The add page automatically generates the id to be used by accessing the database's most recent id and adding one.
My thought was to create a new row in the table every time the add page is opened and give it the calculated id. Then, when information is added it performs a modification to that existing row. This way, if another user opens the add page while another entry is currently being added it will be given the future id, not the same one.
With this method I need a way to delete this entry if the user leaves the add page or closes the browser. Then, I also need other users with open add pages to automatically update their id's to one less when the first user (or any other user less than the most id being used) leaves their add page and cancels the addition.
This is kind of a complicated explanation and if you don't understand let me know and I'll try to answer as best as I can. Any help is much appreciated!
Thanks
There's a number of solutions to your problem, but you seem to have made things harder by having your application generate the record IDs for you.
Instead, you could just be using MySQL's AUTO_INCREMENT functionality to automatically generate/increment the record ID for you (upon insert). MySQL will ensure that there are no duplicates, and you can get rid of the extra database call to retrieve the most recent ID.

Multiple edit of a database table in one form

ok heres my problem.
I have a database table that i want to edit multiple rows by using one form.
I am looking for a way to be able to display a form in which i will be able to edit the rows and save the entries in a grid view kind of way.
Can this be done by dynamically letting the user choose which fields he wants to edit or provide an excel sheet kind of interface where changes are made and saved to this already existing database table.
Using PHP, if you name the form fields as nameoffield[] they will arrive in the request back to the server as an array. Just make sure empty fields have some place holder when they get sent back to the server and just parse through them one by one performing updates/inserts as necessary.

Restrict Joomla article to one view per user

Does anyone know how I can manipulate joomla to only allow one view per user to certain articles? I am looking to make the article gray out and not allow the user to click on it after it has been viewed for the first time. Any help would be much appreciated.
Thank you,
Dave
This is would probably have to be a plugin. This could only really be reliably done on a page that requires a user to be logged in and you can't just register new accounts. Also someone could just copy the text the first time and then your security is moot. Nevertheless, the plugin would have to track the page ID and the user ID and when the visit the page a row gets added to table. Then you could have a page template where you check that table and if the row exists for that page id and user you do whatever to the content otherwise display it as normal.
I'm not sure why you would want to do this, but it would take a plugin that does several things. First, your content would have to be available to registered users only. Cookies would work, but it would be really easy to clear your cookies to regain access to the content. Next, the plugin would need to record every visit to the page, the record would need to include the userID. Last, the plugin would need to look up the specific user that is trying to access an article and check to see if they have been to the page before.
However, all of that work would not prevent anyone from registering another account to access the content again. Or copying and pasting the content or saving the page locally. Why would you want to limit your users to a single page view?
The only correct way to do is create a plugin "content" that will check the database in the field "hits". If it is greater than X, you can redirect Joomla to block his access:
$mainframe->redirect('index.php', JText::_('AN ERROR HAS OCCURED'));
The advantage of this method is that you have the option to reset the counter in the administration of articles
As for the display of the results list, I advise you to use your html file of your template to make such audit and carried away those who are no longer available.

Categories