webmaster1 Posted February 7, 2009 Share Posted February 7, 2009 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. Quote Link to comment Share on other sites More sharing options...
peranha Posted February 7, 2009 Share Posted February 7, 2009 you forgot a closing " <input type="text" name="textfield12" id="textfield12" value="<?php echo $companyname; ?>" /> Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted February 8, 2009 Author Share Posted February 8, 2009 That worked fine but please see original post [modified]. Quote Link to comment Share on other sites More sharing options...
peranha Posted February 8, 2009 Share Posted February 8, 2009 You do it the same way you process any form. It is not dependent on the value attribute. You would just us $_POST['name_of_input'] Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted February 8, 2009 Author Share Posted February 8, 2009 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? Quote Link to comment Share on other sites More sharing options...
peranha Posted February 8, 2009 Share Posted February 8, 2009 I would use an if/else as if the variable isnt set it will throw an error. Quote Link to comment Share on other sites More sharing options...
peranha Posted February 8, 2009 Share Posted February 8, 2009 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. Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted February 8, 2009 Author Share Posted February 8, 2009 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; ?>" Quote Link to comment Share on other sites More sharing options...
peranha Posted February 8, 2009 Share Posted February 8, 2009 NO, it doesnt. It doesnt need to be filled in at all if you process something, the $_POST['name_of_input'] will be blank. The $_POST global goes by the name of the input not the value attribute. in your example it would be $_POST['companyname'] Quote Link to comment Share on other sites More sharing options...
peranha Posted February 8, 2009 Share Posted February 8, 2009 If I dont need it then I wont have a problem having my value set as value="<?php echo $companyname; ?>" No, but if you have error reporting turned on, you will get errors that the variable is not set is it is empty. Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted February 8, 2009 Author Share Posted February 8, 2009 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! Quote Link to comment Share on other sites More sharing options...
peranha Posted February 8, 2009 Share Posted February 8, 2009 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. Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted February 8, 2009 Author Share Posted February 8, 2009 The pages are internal rather than public so should be set there too. Lets hope none of the staff know how to hack though... Quote Link to comment 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.