chewwie Posted April 13, 2008 Share Posted April 13, 2008 Hi guys, I'm kind of new to PHP/MySQL and I have had a google to try and find an answer to my question but so far I have had no luck so I thought I would ask someone. I think my problem is fairly easy to solve its just I cant figure out how to do it! :S Basically I want to submit form data to a new record in a my SQL database. I had it working that on submit it would run a validation script (JavaScript) then if that returned true it would save data to database and replace the form with a confirmation message. That all worked fine. The problem is I actually need to send user to a different page, rather than just echo a confirmation message, as I am parsing some data (unique project code) using a query string to this other page. I don't know how to save data before redirecting! Currently the form validates and the page changes but the data isn't being saved! PHP Script: <?php if (!isset($_POST['submit'])) { ?> <!-- start content --> <div id="content"> <div class="post"> <h1 class="title">/ Create New Project</h1> <form id="createForm" action="" onsubmit="return validateForm()" method="post"> <input blah blah /> </form> </div> </div> <!-- end content --> <?php } else { $title = $_POST['project_title']; $country = $_POST['country']; $city = $_POST['city']; $project = $_POST['description_txt']; $artist = $_POST['artist_name']; $artistage = $_POST['artist_age']; $artisturl = $_POST['artist_url']; $user = $_POST['user_txt']; $query = "INSERT INTO news VALUES ('','$code','$title','$country','$city','$project','$artist','$artistage','$artisturl','$user')"; mysql_query($query); } mysql_close(); ?> Validation: }else{ //A-OK document.getElementById('createForm').action = "viewNew.php?projectCode="+201; return true; } Any suggestions would be greatly appreciated. Thanks Chewwie Quote Link to comment Share on other sites More sharing options...
bobinindia Posted April 13, 2008 Share Posted April 13, 2008 Put ob_start(); at the top of your page. Then header('Location: whereever.php'); on the form processing page. Then ob_flush(); to let it go. Good Luck Quote Link to comment Share on other sites More sharing options...
chewwie Posted April 13, 2008 Author Share Posted April 13, 2008 Sorry guys I was being a complete muppet with my first post! Got it all working now tho. Must have been at that tired stage last night which stopped the brain functioning! Thanks for your suggestion tho bobinindia! I didn't need to try it in the end but i'm sure it would have also worked! Cheers 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.