The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

4 Pages V  1 2 3 > »   
Reply to this topicStart new topic
> mysql table row update/modify with a html form radio button selected row
shankar from vizag
post Jun 8 2015, 11:20 AM
Post #1


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316





I have a report having the following mysql columns and buttons like UPDATE AND DELETE RECORD

select (radio button) | Serial No. | column1 | column 2 so on....

I stuck with update record which is selected by the user by radio button selection.

How can I update a record in an easy way.

Kindly provide solution. I thank in advance.Attached Image
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 8 2015, 11:52 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I doubt anyone will 'provide solution' but maybe someone can help. Post your code.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 9 2015, 11:11 AM
Post #3


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Jun 9 2015, 10:22 AM) *

I doubt anyone will 'provide solution' but maybe someone can help. Post your code.


Thank you verymuch charles!!

I am attaching all my php, html pages relating to this topic. conferences.sql is the mysql table. In my system dir_office is the database I used to store the table.
I have attached all html and php files with which I got the report shape.
Now, how can I update the existed records in the table with html report form. In the report page I have radio button to select any row which require amendment.
When the user select a row and click on the UPDATE button, the entire row data should appear on the new page with an UPDATE button. Then the user can have the facility to modify the record date. This is what the concept.

Now, how can I fetch the selected row to another page and display in textboxes for amendment.

Kindlly help. I hope you understand my problem well. Waiting for your reply.
Attached File  for_update_solution.rar ( 3.13k ) Number of downloads: 699
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 10 2015, 07:24 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I have looked over your code but in order to get it to run on my system I would have to create the database table, which I will not do.

First the pages I have looked at do not have the correct HTML structure. Take "rpt_conference.html", for example. This is your code:
CODE
<!DOCTYPE html>
<html></html>
<body>
    <form action="rpt_conference.php" method = "post">
<center><input type = "submit" name="submit" value="Get Report"/></center>
</form>
        </body>

The correct structure should be:
CODE
<!DOCTYPE html>
<html>
<body>
  <form action="rpt_conference.php" method = "post">
  <center><input type = "submit" name="submit" value="Get Report"/></center>
</form>
</html>
</body>

The <center> tag is not supported in HTML5. You should use CSS instead. HTML does not require the closing '/' character. 'mysql' commands are deprecated in PHP you should use either 'myslqi' or 'PDO' commands. If you look at "rpt_conference.php" you will see that your PHP code is completely outside the HTML document. I'm sure there are more problems but that is all I can say for now. Based on your code it appears "rpt_conference.php" will build a table with your data. You have named the radio button 'select' which means each entry will have the same radio button name, also you forgot the closing </tr> tag. Since all the rows have the same name that means only 1 row can be selected at a time. Your radio button should also have a 'value' attribute which should have the row 'id' assigned. When the form is submitted you get the value of the radio button and use it in your query to retrieve the data record.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 10 2015, 11:28 AM
Post #5


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316




Sir, thank you so much for your valuable suggestions.

I have rectified them as suggested. If I did not use the same name for the radio button, the function of selection is not working properly. If I use different names for each radio button, every radio button is getting checked rather single option. Moreover, there is no limit for rows as entries have no end. Hence, I keep the radio button creation under "while loop". In this I cannot give individual naming. The data base name is "dir_office" and the table conference.sql I have mailed to you, in which id is there.

How can the ID of a row be captured with radio button selection and pass those record values to the corresponding text boxes of the update page for updating the values.

Hope you understand my problem. Please guide me to overcome this problem.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 10 2015, 11:42 AM
Post #6


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



You would keep the radio button naming the same. It has to be that way. But you do need to add a 'value' attribute to the radio button, as such:
CODE
echo '<input type="radio" name="select" value="$res['id']">';
This assumes you want to use the 'id' value to retrieve the data record.

This post has been edited by CharlesEF: Jun 10 2015, 11:42 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 10 2015, 11:59 AM
Post #7


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



THE FOLLOWING CODE I PUT IN "upd_conferences.php" to fetch the mysql table row date and display in the corresponding textboxes for updating if required.

<?php
$connection = mysql_connect("localhost", "root", "") or die("error");
mysql_select_db("dir_office", $connect);
$sql="SELECT * from conferences where id=$_POST['id']";
$result=mysql_query($sql, $connect);
while($res=mysql_fetch_array($result))
{
$id = $res['id'];
$date=$res['date'];
$time=$res['time'];
$sub=$res['subject'];
$meeting=$res['type_meeting'];
$venue = $res['venue'];
$lo=$res['Liason_officer'];
$div=$res['divisions_involved'];
$mem=$res['outside_mem'];
$con=$res['conclusion'];
}
?>
<html>
<body>
<table>
<tr><td>ID</td><td><input type="text" value='<?php echo $id;?>'</td></tr>
<tr><td>DATE</td><td><input type="text" value='<?php echo $date;?>'</td></tr>
<tr><td>TIME</td><td><input type="text" value='<?php echo $time;?>'</td></tr>
<tr><td>SUBJECT</td><td><input type="text" value='<?php echo $sub;?>'</td></tr>
<tr><td>MEETING</td><td><input type="text" value='<?php echo $meeting;?>'</td></tr>
<tr><td>VENUE</td><td><input type="text" value='<?php echo $venue;?>'</td></tr>
<tr><td>LO</td><td><input type="text" value='<?php echo $lo;?>'</td></tr>
<tr><td>DIVISIONS</td><td><input type="text" value='<?php echo $div;?>'</td></tr>
<tr><td>OUTSIDE MEMBERS</td><td><input type="text" value='<?php echo $mem;?>'</td></tr>
<tr><td>CONCLUSION</td><td><input type="text" value='<?php echo $con;?>'</td></tr>
</table>


</body>

</html>
-----------------------------------------------------------------------------------------------------------
Here what I am not understanding is,

how can I post values other than submit button. In this case, on clicking UPDATE RECORD button the action should take place. What is the procedure in this type of action.

Secondly, on selection of the mysql record by the radio button, how can I pass through the above button to the upd_conferences.php file.

I am awaiting for the valuable reply.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 10 2015, 01:07 PM
Post #8


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I think you want this line:
CODE
$sql="SELECT * from conferences where id=$_POST['id']";
to be this:
CODE
$sql="SELECT * from conferences where id=$_POST['select']";


If I understand the rest of your question correctly, I would forget about using javascript (the print command is ok). Use PHP instead by placing the entire data section inside a <form> ... </form>. You will need buttons of 'type="submit"' but you can name them 'Update' and 'Delete' or anything else you want. The form would submit to 1 php page where you can have 2 sections defined, 1 to update and 1 to delete. Check to see which submit button was clicked and perform your action form there. If you name the buttons 'Update' and 'Delete' then use the isset() command to check which button was clicked.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 11 2015, 02:03 AM
Post #9


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Jun 10 2015, 11:37 PM) *

I think you want this line:
CODE
$sql="SELECT * from conferences where id=$_POST['id']";
to be this:
CODE
$sql="SELECT * from conferences where id=$_POST['select']";


If I understand the rest of your question correctly, I would forget about using javascript (the print command is ok). Use PHP instead by placing the entire data section inside a <form> ... </form>. You will need buttons of 'type="submit"' but you can name them 'Update' and 'Delete' or anything else you want. The form would submit to 1 php page where you can have 2 sections defined, 1 to update and 1 to delete. Check to see which submit button was clicked and perform your action form there. If you name the buttons 'Update' and 'Delete' then use the isset() command to check which button was clicked.


Sir thank you for your response.

Here what I have the confusion is the usage of isset. Can you give an example to use this for UDPATE and DELTE command buttons.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 11 2015, 02:27 AM
Post #10


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



CODE
if(isset($_POST['Delete']))
{
  code to run when Delete button is clicked
}
if(isset($_POST['Update']))
{
  code to run when Update button is clicked
}
That's all there is to it. If you have more questions then update your code and post it here so I can see your progress.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 11 2015, 03:37 AM
Post #11


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Attached is a small sample file. I have hard coded everything and you will need to convert some of the code to PHP in order to get it to work for you. It should provide enough of a sample for you. If you have any questions then just post back.
Attached File  testform.php ( 2.76k ) Number of downloads: 1034
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 11 2015, 05:10 AM
Post #12


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Jun 11 2015, 02:07 PM) *

Attached is a small sample file. I have hard coded everything and you will need to convert some of the code to PHP in order to get it to work for you. It should provide enough of a sample for you. If you have any questions then just post back.
Attached File  testform.php ( 2.76k ) Number of downloads: 1034




THANK YOU SOOOOO MUCH SIR. I WILL TRY THE CODE AND LET YOU KNOW.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 11 2015, 11:05 AM
Post #13


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Jun 11 2015, 02:07 PM) *

Attached is a small sample file. I have hard coded everything and you will need to convert some of the code to PHP in order to get it to work for you. It should provide enough of a sample for you. If you have any questions then just post back.
Attached File  testform.php ( 2.76k ) Number of downloads: 1034



Sir,

I have tried and got the following error while running the page:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\director-page\upd_conferences.php on line 4

at the 4th line of the upd_conferences.php the code is: $sql="SELECT * from conferences WHERE id=$_POST['select']";

I have tried without using WHERE clause, then the page is successfully working and showing the last row of the table.

It means the WHERE clause has the problem. In my code all radio buttons are forming with while loop and hence the name of all radio button will be similar i.e. "select". It might be the reason of failure. As per my opinion 'CHECKED' word may work because the CHECKED row only I have to display on another page. But not understanding how to mention it in the code.

How can I overcome this problem..

waiting for your early reply

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 11 2015, 11:48 AM
Post #14


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



You need to post your current code. My sample file does not contain a '$sql=' at all, so I assume your problem is with your code. Post the code.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 12 2015, 01:00 AM
Post #15


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Jun 11 2015, 10:18 PM) *

You need to post your current code. My sample file does not contain a '$sql=' at all, so I assume your problem is with your code. Post the code.


Sir,

firstly I am trying to fetch the data of a selected row by a radio button and display the same on upd_conferences.php on clicking the UPDATE RECORD button. The code on upd_conferences.php is as follows:

On update button I just put the redirection line like <input type = "button" name = "update" onclick="window.location.href='upd_conferences.php';">
------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
$connect = mysql_connect("localhost", "root", "") or die("error");
mysql_select_db("dir_office", $connect);
$sql="SELECT * from conferences where id=$_POST['select']"; //on running the page error is showing here[color=#3366FF]
$result=mysql_query($sql, $connect);
while($res=mysql_fetch_array($result))
{
$id = $res['id'];
$date=$res['date'];
$time=$res['time'];
$sub=$res['subject'];
$meeting=$res['type_meeting'];
$venue = $res['venue'];
$lo=$res['Liason_officer'];
$div=$res['divisions_involved'];
$mem=$res['outside_mem'];
$con=$res['conclusion'];
}
?>
<html>
<body>
<table>
<tr><td>ID</td><td><input type="text" value='<?php echo $id;?>'</td></tr>
<tr><td>DATE</td><td><input type="text" value='<?php echo $date;?>'</td></tr>
<tr><td>TIME</td><td><input type="text" value='<?php echo $time;?>'</td></tr>
<tr><td>SUBJECT</td><td><input type="text" value='<?php echo $sub;?>'</td></tr>
<tr><td>MEETING</td><td><input type="text" value='<?php echo $meeting;?>'</td></tr>
<tr><td>VENUE</td><td><input type="text" value='<?php echo $venue;?>'</td></tr>
<tr><td>LO</td><td><input type="text" value='<?php echo $lo;?>'</td></tr>
<tr><td>DIVISIONS</td><td><input type="text" value='<?php echo $div;?>'</td></tr>
<tr><td>OUTSIDE MEMBERS</td><td><input type="text" value='<?php echo $mem;?>'</td></tr>
<tr><td>CONCLUSION</td><td><input type="text" value='<?php echo $con;?>'</td></tr>
</table>


</body>

</html>
--------------------------------------------------------------------------------------------------------------------------------------------

here I want to tell you that, when I removed the WHERE clause of the SELECT sql option, its working fine but displaying last row details on the corresponding textboxes.

Kindly correct me where I mistaken.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 12 2015, 04:31 AM
Post #16


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I don't understand your logic for using javascript to redirect to another page. Without using the javascript form submit command does the form even submit? I don't know the answer and I don't have the time to figure it out. I suggest you stick with PHP for all this. I have changed my testform.php to give you an example. Download the page and rename it to 'rpt_conference.php'. I have made no other changes and I can't test it. If there are errors it must be in your PHP code. The update action uses the PHP header command to redirect to 'upd_conferences.php' with an id query string addition. This means that the first line of code in 'upd_conferences.php' should be '$id = $_GET['id'];' to set the id value for the record to retrieve. My form is still not complete, it needs some error checking code. What should happen if the user clicks 'update' or 'delete' without selecting a row first?
Attached File  testform.php ( 2.2k ) Number of downloads: 668


This post has been edited by CharlesEF: Jun 12 2015, 04:32 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 12 2015, 06:41 AM
Post #17


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



If you really want to use javascript then try this:
CODE
<input type="button" name="update" value="Update Record" onclick="window.location.href='upd_conferences.php?id=' + document.testform.select.value;">
This code assumes that the form ID is 'testform' and the radio button ID is 'select'. This will redirect to 'upd_conferences.php' with an id query string addition, so you still need to use this code as the first line in 'upd_conferences.php':
CODE
$id = $_GET['id'];
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Jun 12 2015, 11:31 AM
Post #18


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Jun 12 2015, 05:11 PM) *

If you really want to use javascript then try this:
CODE
<input type="button" name="update" value="Update Record" onclick="window.location.href='upd_conferences.php?id=' + document.testform.select.value;">
This code assumes that the form ID is 'testform' and the radio button ID is 'select'. This will redirect to 'upd_conferences.php' with an id query string addition, so you still need to use this code as the first line in 'upd_conferences.php':
CODE
$id = $_GET['id'];



Sir

I have added php code for redirecting to upd_conferences.php in the rpt_conferences.php file. Both files I have attached. When I run and clicking on the update button nothing is happening. Whats wrong with the code I am not understanding. Please do help sir. Attached File  rpt_conference.php ( 2.29k ) Number of downloads: 592
Attached File  upd_conferences.php ( 1.51k ) Number of downloads: 599
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 12 2015, 11:58 AM
Post #19


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



The HTML structure in 'rpt_conference.php' was still wrong. I think I have corrected it. In 'upd_conferences.php' you are not reading the id query string value so you had no record id to retrieve. I think I have corrected this also. Try the corrected versions and let me know.
Attached File  rpt_conference.php ( 2.3k ) Number of downloads: 750
Attached File  upd_conferences.php ( 1.43k ) Number of downloads: 700
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jun 12 2015, 03:28 PM
Post #20


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Something was bothering me about your code so I went back and looked over it again. I found 2 more problems that you need to fix. 'rpt_conference.php' contains 2 input fields of type="button", the update and delete buttons. Both of these need to be type="submit". Make this change before you run the 2 scripts I corrected.

I hate to say this but it seems you did not really look over my samples. You made some of the changes but missed a lot of others.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

4 Pages V  1 2 3 > » 
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 12:34 PM