jadedknight Posted February 28, 2007 Share Posted February 28, 2007 Soo 10 min later Im back at it again I would like my script to redirect after I submit and process the form. Form Code. require('db-connect.php'); $title = $_POST['title']; $author = $_POST['author']; $date = $_POST['date']; $content = $_POST['content']; $query = "INSERT INTO posts (title, author, date, content) VALUES ('$title', '$author', '$date', '$content')"; if (mysql_query($query)) { print "<script language=\"Javascript\">document.location.replace('index.php')</script >"; } else { die(mysql_error()); } mysql_close(); ?> <form id="form-post" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Title:</p> <p><input class="required" id="field-title" type="text" name="title" /></p> <p>Author:</p> <p><input class="required" id="field-author" type="text" name="author" /></p> <p>Date:</p> <p><input class="required" id="field-date" type="text" name="date" /></p> <p>Content: </p> <p><textarea class="required" id="field-content" name="content" rows="5" cols="50"></textarea></p> <p><input type="submit" value="Submit Post" /></p> <p><input type="reset" value="Reset Fields" onclick="valid.reset(); return false" /></p> </form> As you can see I am trying to redirect within an IF statement, however in its current state the $query check is always true, so I cant even access the page. How do I go about redirecting? Thank you ^^ Link to comment https://forums.phpfreaks.com/topic/40452-solved-redirect-on-submit-with-form-using-_serverphp_self/ Share on other sites More sharing options...
pocobueno1388 Posted February 28, 2007 Share Posted February 28, 2007 Hello again xP if (mysql_query($query)) { header("Location: index.php"); } else { die(mysql_error()); } That just may work...don't hold me to it though =) Link to comment https://forums.phpfreaks.com/topic/40452-solved-redirect-on-submit-with-form-using-_serverphp_self/#findComment-195749 Share on other sites More sharing options...
jadedknight Posted February 28, 2007 Author Share Posted February 28, 2007 I am pretty sure that can only be used in the actual header, but I decided to change the form action to an external page. Link to comment https://forums.phpfreaks.com/topic/40452-solved-redirect-on-submit-with-form-using-_serverphp_self/#findComment-195752 Share on other sites More sharing options...
pocobueno1388 Posted February 28, 2007 Share Posted February 28, 2007 Awesome, does this mean the topic is solved? EDIT: Nevermind ^^ Link to comment https://forums.phpfreaks.com/topic/40452-solved-redirect-on-submit-with-form-using-_serverphp_self/#findComment-195754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.