Jump to content

Recommended Posts

Hi Everyone,

 

I have a form that when submitted, sends the data into the database.  What I am looking for is that when someone later comes back to this form, the current data from the database is in the text fields, able to be edited, and resent to the database.

 

Does anyone know how to do this?

 

Thank you all very much.

But if the data changed, wouldn't I have to manually change the <input value=" ">?  Is there a way that it would automatically show the data in the text field the next time I came back to change the data.

 

Thanks

Others said it, but im giving a real example so u understand it right:

 

<?php
//update the db info if the form is submitted. This "if" part can aslo be in another page.
if(isset($_POST['text'])){
if($_POST['text'] != ''){
	$text = $_POST['text'];
	$textid = $_POST['id'];
	$resultsUpdate = mysql_query("UPDATE table SET text='$text' WHERE id=$textid");
	echo 'The text was updated successfuly';
} else{
	echo 'The field cant be empty.';
}
}
$id = 10; //just for the example's sake
$results = mysql_query("SELECT text FROM table WHERE id=$id");
$values = mysql_fetch_array($resuslts);
?>
<form id="myForm" name="myForm" method="post" action="mypage.php">
  <input type="text" name="text" value="<?php echo $values['text']; ?>" />
  <input type="hidden" name="textid" value="<?php echo $id; ?>" />
  <input type="submit" name="Submit" value="Submit" />
</form>

Thanks everyone.

 

What about for drop down menus.

 

Where in:

 

<select name="in2">

  <option value=" "> </option>

  <option value="Person1">Person1:</option>

  <option value="Person2">Person2:</option>

  <option value="Person3">Person3:</option>

  <option value="Person4">Person4:</option>

</select>

 

Would I fit the previous answer?

Well I guess you got the <input>s working then?  :P

Anyway, they're a bit different but still simple, since you can't just change the value, instead do something like this:

<option value="Option1" <?php if ($nameofvariableforthisselect == "Option1") echo 'selected="selected"'; ?>>Option1</option>

This will cause the option to be selected if the variable is equal to it's value.

I got the inputs working.  Thanks a lot for that. You saved me a bigger headache.

 

I'm not quite getting what you're saying about the part you just input.

 

<?php if ($nameofvariableforthisselect == "Option1") echo 'selected="selected"'; ?>

 

 

Just insert that in the <option> tag like shown and replace Option1 with the value of the <option> you put it in and replace the $nameofvariableforthisselect variable with the variable containing the value you took from the database like you did for the <input>s. And do that for every <option> tag.

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.