redgunner Posted August 25, 2010 Share Posted August 25, 2010 Hi, I have this form currently setup and is showing the value from the table. <form action="updaterates.php" method="post"> <table width="350"> <tr> <td width="100">7 Nights</td> <td width="100"><input type="text" name="rates1" value="<?php echo ($row['rates1']); ?>" maxlength="3" size="3"></td> </tr> </table> </form> What do I need to do in order for it to update the value in the table... Thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/211662-form-to-change-values-of-column/ Share on other sites More sharing options...
MadTechie Posted August 25, 2010 Share Posted August 25, 2010 okay first of all add, in your database do you have a primary key that is auto-numbered ? I assume you have and its name is ID, okay first add a text field to your form, where call that ID as well <input type="text" name="ID" value="<?php echo ($row['ID']); ?>" /> Don't worry about what it looks like for now where going to hide it later, also add a add a submit button Now on updaterates.php we're going to need to take ID and update the rates1 of that record so the code should look like this (basic example) <?php //Check IF ID was posted if(!empty($_POST['ID'])){ //DATABASE connection etc //Query, $query="UPDATE table SET rates1='".$_POST['rates1']."' WHERE ID=".$_POST['ID']; } ?> Now change the text field to hidden field <input type="hidden" name="ID" value="<?php echo ($row['ID']); ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/211662-form-to-change-values-of-column/#findComment-1103439 Share on other sites More sharing options...
redgunner Posted August 25, 2010 Author Share Posted August 25, 2010 Thank you... Resolved it with this code =) Thanks for helping me learn this <?php $username="root"; $password=""; $database="mydb"; $connection = mysql_connect("localhost", $username, $password) or die("Connection Failure to Database"); mysql_select_db($database, $connection) or die ($database . "No Database" . $username); $query="UPDATE settings SET rates1='".$_POST['rates1']."' WHERE ID=".$_POST['id']; mysql_query($query) or die(mysql_error()); echo ($_POST['rates1']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/211662-form-to-change-values-of-column/#findComment-1103554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.