Jump to content

Form to change values of column...


redgunner

Recommended Posts

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...

Link to comment
Share on other sites

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']); ?>" />

Link to comment
Share on other sites

Thank you... Resolved it with this code =) Thanks for helping me learn this ;D

 

<?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']);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.