DeFActo Posted April 10, 2008 Share Posted April 10, 2008 Hello all, i want to update records in table and have that code: <? // Connect database. $host="localhost"; // Host name. $db_user=""; // MySQL username. $db_password=""; // MySQL password. $database=""; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $result=mysql_query("select * from kol where id='1'"); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="update_1.php"> <table border="1" cellpadding="3" cellspacing="0"> <tr> <td align="center" bgcolor="#FFCC00"><strong>ID</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Name</strong></td> </tr> <? while($row=mysql_fetch_assoc($result)){ ?> <tr> <td bgcolor="#FFFFCC<? echo $row['id']; $aa=$row['id']; ?></td> <td bgcolor="#FFFFCC"><input name="name_<? echo $row['id']; ?>" type="text" id="name_<? echo $row['id']; ?>" value="<? echo $row['name']; ?>" /></td> </tr> <? } ?> </table> <input type="submit" name="Submit" value="Update" /> </form> </body> </html> everything would be perfect, but as you can see i want to update just one row. I know that i could do it like that: <input name="id_<? echo $row['id']; ?>" type="text" id="id_<? echo $row['id']; ?>" <!--value="<? echo $row['id']; ?>" /> and then in update_1.php: $a=$_POST['id']; but i do not want that $row['id'] would be changeable. Any hints how could i do it? Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/100499-solved-update-records/ Share on other sites More sharing options...
craygo Posted April 10, 2008 Share Posted April 10, 2008 what you do is store the row id in a hidden field <input type="hidden" name="id" value="<?php echo $row['id']; ?>" /> Ray Link to comment https://forums.phpfreaks.com/topic/100499-solved-update-records/#findComment-513948 Share on other sites More sharing options...
DeFActo Posted April 10, 2008 Author Share Posted April 10, 2008 oops, sorry, wrong line: <input name="id_<? echo $row['id']; ?>" type="text" id="id_<? echo $row['id']; ?>" value="<? echo $row['id']; ?>" /> Link to comment https://forums.phpfreaks.com/topic/100499-solved-update-records/#findComment-513951 Share on other sites More sharing options...
craygo Posted April 10, 2008 Share Posted April 10, 2008 not sure why you posted that but you would replace that line with the one i posted above. then one you submit you would get the id with $a = $_POST['id']; You won't have to put the id with the name anymore <input name="name" type="text" id="name_<? echo $row['id']; ?>" value="<? echo $row['name']; ?>" /> Ray Link to comment https://forums.phpfreaks.com/topic/100499-solved-update-records/#findComment-513962 Share on other sites More sharing options...
DeFActo Posted April 10, 2008 Author Share Posted April 10, 2008 Thanks a lot Ray, the line you typed works, but the strange thing is that i've tried to do it that way as well before i made this topic, but it did not work for me. well maybe i made somewhere mistake. now it works and thank you again. problem solved. Link to comment https://forums.phpfreaks.com/topic/100499-solved-update-records/#findComment-513968 Share on other sites More sharing options...
craygo Posted April 10, 2008 Share Posted April 10, 2008 hidden inputs will not work if you use the GET method in your form, will only work with POST. Link to comment https://forums.phpfreaks.com/topic/100499-solved-update-records/#findComment-513973 Share on other sites More sharing options...
DeFActo Posted April 10, 2008 Author Share Posted April 10, 2008 OK, thanks for info. Link to comment https://forums.phpfreaks.com/topic/100499-solved-update-records/#findComment-513980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.