pluto Posted December 17, 2008 Share Posted December 17, 2008 Dear all, I've managed to do the bits I've wanted in terms of adding words to data bases, and ensuring that they don't exist etc. However, I've come across an interesting problem. Ideally, I'd like the screen to go back to the HTML input form once a record has been added, but I can't seem to work out how to do that. I've read about URLREFERER or something like that somewhere, but I was wondering if anyone had other ideas? Many thanks Pluto Quote Link to comment Share on other sites More sharing options...
twm Posted December 17, 2008 Share Posted December 17, 2008 submit the page to itself , then process your data, or check out: http://us.php.net/manual/en/function.header.php Quote Link to comment Share on other sites More sharing options...
pluto Posted December 17, 2008 Author Share Posted December 17, 2008 Alas, When I tried the header, I got the following error: word exists Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\insert_word.php:9) in C:\xampp\htdocs\insert_word.php on line 11 This is my code... <?php // Open the data base connection $conn = mysql_connect("localhost","root",""); mysql_select_db("test",$conn); // check that the word exists first. $check = "SELECT * FROM TEST2 where word = '$_POST[word]"; if($check==true) { echo "word exists"; // load the previous page again header('Location:http://localhost/insert_test.html'); exit; } else { $sql = "INSERT INTO test2 values ('','$_POST[word]','$_POST[definition]','$_POST[chapter]','$_POST[section]')"; if(mysql_query($sql, $conn)) { // check that the word doesn't already exists echo "record added"; } else { echo "Error in entering the record"; } } ?> Ideally, I'd like the warning to come in red under the text box in the HTML page, but that'll come with further practice I'm sure, and that's a different issue. Thanks in advance Pluto Quote Link to comment Share on other sites More sharing options...
twm Posted December 17, 2008 Share Posted December 17, 2008 your script can not have any output before calling the header function Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted December 17, 2008 Share Posted December 17, 2008 also check into mysql injection solutions... inserting raw data into a db table can be very dangerous 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.