How to select row from table? - php

I have created a table that displays the results from a MYSQL database. At the end of each row, I have added a button that when clicked on inserts the session username into the database. Apart from the session username I want to insert all the other details present in the table ROW in which the button is present.
How do I do that?

I presume you have some sort of form for each row to hold your submit button?
If thats the case you can use hidden field form elements. in each cell of the row add an hidden field and set the values. upon when the user submits that info is passed to via POST or GET. Be warned that doing this means the user could tamper with the data before submitting entering invalid info.
To avoid the above issue you can just pass the ID of the row to the form and on submit read the id, get the result for the DB and then insert into into another table or database.

Related

Complete data with a query of the same form data in php

I want to use a php code to return an email based on a query with another data from the same form?
For example, I have a table with 2 columns, user and email, the user complete the form with the username that match with the user column in the DB, and then the email filled is complete with the email column value without use a submit button.
I only have a continue button between steps.
Exists anyway to do this?
Regards

Inserting dynamically generated form data into mysql

I have a simple HTML form with three fields name,school and city. Also within the form, I have a button which I am using to insert a sub form with values neighbourhood and population. The crud mechanism is using jquery append.
In my database, I am saving the main form data in one table and the sub form data in another table.
My question is, during the creation of data in the main form, if I insert the data of the main form into one table and get the last inserted Id and use the id as a reference when inserting data into the second table, will this approach always work in both mysql and ms SQL?
If not is there a better approach I can adopt?
It will work, as long as your dynamically created input has the proper name attribute..
For example: name="txt_neighbourhood"

How to add data to one table from two different form using PHP and jquery?

I have one table example: ( Name,city,Occupation ,Education,hobbies,Citizen,SSN ) but 2 data entry forms.
In the first form If I enter the data.(Name,City,Occupation)
When I click one button it should go to the next form and there I should enter the rest (Education,hobbies,Citizen,SSN).
Problem..
When I go to the next form it takes it as the next record.Like
(Name,City,Occupation) is saved in one record in the database.
and when I go the nextform it saves the rest to the new record.
Please help me with this issue as I am new to this language.
PS: I am using mysql Database with Php.
You are inserting data on 2nd screen. You should update the record by using row Id of the data inserted in the first screen.
Don't insert values from the 1st form into the db right away.
Instead call form2 in the action part of form1.
Extract the values from form1 and populate them in hidden variables in form2....something like:
<form id="f2"...>
<?php
echo "\n<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
?>
</form>
When the second form gets submitted, extract the hidden form fields and insert them into the db in one go.

html table with data from database without populating database row id php

I am constructing html table with data queried from database using php. I also need to perform edit,delete operations on that table. I am saving the
database row id as hidden input field in each table row.
What I am doing is when user clicks on the particular row I getting the row id using jquery and performing edit/delete operations on the database table
using ajax,php
But the problem here is when user inspects element he can see the ids of each row. So if the user is technical expert he can edit the row id and change the
value of other rows in database table.
Generally how to handle this type of situations without populating database row id in table.
If the user is that kind of expert to look in inspector and manipulate that hidden info, and that is something that has to be strictly not possible to change, you could send guid or some custom backend function that encrypt / decrypt the info from user table..
Populating the row id is a correct, but if the user can change the values of some records but not others, the correct solution would be check server-side if the user has the privileges to edit the row that is currently trying to edit
You can take more info from the any cell of the row.
You save the id in your hidden input then take with jquery any cell and if the data cell and the id are not same in DB don't do anything if have relation then Delete.
hope it will be useful
For more security you have to create hash of each row and send to ajax page and verify both the hash . since it is a one way encryption so you hash for each row is unique..
Here is what i am saying to you
https://www.owasp.org/index.php/How_to_protect_sensitive_data_in_URL's

Inserting check boxes next to MySQL database output in the form of HTML table

I've been trying to insert check boxes next to values retrieved from a MySQL table and the output is in the form of a HTML table.
The output is on the same page as the query form which will retrieve the values in the form of the table above. Now, I wish to insert check boxes beside each row/entry received from the database and use it to update the notification_sent column in the database, but so far I've hit a roadblock with this.
Just add one more td with the checkbox code:
<td><input type="checkbox" name="notification_sent[]"/></td>

Categories