Jump to content

[SOLVED] Quicky: How do display default text in a regular text box?


webmaster1

Recommended Posts

I've modified the original post to make more sense:

 

I'm exporting several fields of a table into form.

 

Each field is displayed in text box by echoing the variable as its value.

 

The user can then modify the text box.

 

The confirm button is pressed and the form overwrites the record.

 

QUESTION: HOW CAN I USE THE VALUE ATTRIBUTE TO WRITE BACK TO MY DATABASE IF IM USING IT TO PULL DATA INTO IT?

 

I hope this makes more sense.

Link to comment
Share on other sites

But the way I've learned it I use the value in the following way to post the input and write it back to my database:

 

 <input type="text" name="companyname" id="companyname" class="text" value="<?php if (isset($_POST['companyname'])) echo $_POST['companyname']; ?>"/>

 

Do I even need that "if isset" piece as the value? Are you saying its obsolete?

 

And if I so doesn't that prevent me from using the value to display a default value? Should I use an if else statement?

Link to comment
Share on other sites

I am confused at your question now.

 

The value attribute fills in the box for you.  if you want to insert the data back into the database you would do it the same way you process any form.  You have a submit button and when clicked, process it.

 

Not saying anything about obsolete.

Link to comment
Share on other sites

Sorry for the confusion.

 

I guess my question is do I need to have the 'if isset' part as my value for the post to work or does it pick up the value by the id or name or something like that?

 

I have my value set as value="<?php if (isset($_POST['companyname'])) echo $_POST['companyname']; ?>"

 

Does it need to be like that for the post to work? (thats what I meant by obsolete, sry)

 

If I dont need it then I wont have a problem having my value set as value="<?php echo $companyname; ?>"

Link to comment
Share on other sites

It all makes sense now. I also see what you mean about the error handling. I won't be validating any of the fields since the user has free reign to add, edit and delete as they see fit so I should be set.

 

Thanks so much peranha!  :-*

 

You way want to make sure that they are free from sql injections and XSS attacks so you dont get hacked.

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.