Lassie Posted February 3, 2014 Share Posted February 3, 2014 I am experimenting with capturing the result of a form , storing the result in a database and visiting the page. I am using the header function but can't get a result. Is this the right way to do it and how can I get it to work please. File attached untitled text 2.html Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 3, 2014 Share Posted February 3, 2014 header() statements can only be used before any content has been sent to the browser (content being anything other than a header.) do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would be displaying an error when you have tried to use a header() after content has been sent to the browser? lastly, .html files by default are not passed to the php language engine to even parse the php code in it. have you configured your sever to invoke php for the .html file extension? Quote Link to comment Share on other sites More sharing options...
Lassie Posted February 3, 2014 Author Share Posted February 3, 2014 I will check the points you raise and get back. The file is a php file I just copied the code into text wrangler in order to attach the file. Thanks Quote Link to comment Share on other sites More sharing options...
.josh Posted February 3, 2014 Share Posted February 3, 2014 Looking at your code, I can confirm what mac_gyver said: you need to restructure your code to have header() be called before any output. Also, you will need to add exit(); immediately after the redirect, so that php will stop parsing/outputting the rest of the script. couple of sidenotes: - mysql_xxx functions are deprecated. You should at a minimum update your mysql functions to use the mysqli syntax. It has both object oriented and procedural syntax. The procedural syntax is very similar to the mysql procedural syntax you already used, so updating it is relatively painless. Better yet, look into using prepared statements, like with the PDO class. - I see a comment in your code to sanitize the user input but you aren't actually doing that. If you do not validate/sanitize the user input, you are begging for your site to be hacked. Switching to prepared statements will take care of this, but at a minimum you should be validating that the data is expected format/values. 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.