brad12345 Posted April 11, 2008 Share Posted April 11, 2008 hi all i have a condition when a statement runs if it is tru i would like to redirect the browser back to another page if(empty($petName) || empty($petSpecies) || empty($petBreed)) { //here is the code hopefully i can run to take them back to the page before.... } thanks all Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted April 11, 2008 Share Posted April 11, 2008 header("Location: http://www.website.com/redirect_here.php"); replace http://www.website.com/redirect_here.php with the URL of where you want to redirect them to Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 Don't forget that the header command has to be sent before anything at all is sent to the browser. Quote Link to comment Share on other sites More sharing options...
brad12345 Posted April 11, 2008 Author Share Posted April 11, 2008 Warning: Cannot modify header information - headers already sent by (output started at /home/it224/bradk/public_html/assignment1/newPatient.php:11) in Error coming back? also a note it is not just a php script, the php script is inside the html, should this effect it? Quote Link to comment Share on other sites More sharing options...
brad12345 Posted April 11, 2008 Author Share Posted April 11, 2008 well then how am i supposed to run that code maybe this will give better understanding //Patient POST vaiables $addPatient = $_POST['addPatient']; $petName = $_POST['petName']; $petSpecies = $_POST['petSpecies']; $petBreed = $_POST['petBreed']; $petAge = $_POST['petAge']; $petWeight = $_POST['petWeight']; $ownerID = $_POST['ownerID']; echo("<font face='Arial'>"); $self = $_SERVER['PHP_SELF']; //If a patient has been added from the form being filled out and 'addPatient' = true the preform below code if (isset($_POST['addPatient'])){ if(empty($petName) || empty($petSpecies) || empty($petBreed)) { header("Location: http://kate/~bradk/newPatient.php"); } //Adding patient into database $createQuery2 = "INSERT INTO tblPatientBK (petName, petSpecies, petBreed, petAge, petWeight, ownerID) VALUES ('$petName','$petSpecies','$petBreed','$petAge','$petWeight','$ownerID')"; $result = mysql_query($createQuery2); //preforming mysql $createQuery2 //displaying message to let user know the task has been carryed out and the patient has been added echo ("Thank you<p>Your new patient has been added successfully.<p>"); echo("<a href='index.php'><font color='blue'>Return to home page</font></a>"); } else also above all that is <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Veterinarian Patient Management Tool</title> <link rel="stylesheet" type="text/css" href="stylesheet.css" /></head> <body> <div id="wrap"> <div class="header"></div> <div class="pageTitle"><a href="index.php">Home</a> | <a href="newOwner.php">Add New Owner</a> | <a href="newPatient.php">Add New Patient</a> | <a href="deletePatient.php">Delete a Patient</a> | <a href="echoDB.php">Report</a> | <a href="search.php">Search</a></div> <div class="content"> Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 11, 2008 Share Posted April 11, 2008 Warning: Cannot modify header information - headers already sent by (output started at /home/it224/bradk/public_html/assignment1/newPatient.php:11) in Error coming back? also a note it is not just a php script, the php script is inside the html, should this effect it? Yes--that error message is exactly what you get if you use the header cmd and have already sent anything to the browswer. Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted April 11, 2008 Share Posted April 11, 2008 put this code on top of the html <?php if (isset($_POST['addPatient'])){ if(empty($petName) || empty($petSpecies) || empty($petBreed)) { header("Location: http://kate/~bradk/newPatient.php"); } //Adding patient into database $createQuery2 = "INSERT INTO tblPatientBK (petName, petSpecies, petBreed, petAge, petWeight, ownerID) VALUES ('$petName','$petSpecies','$petBreed','$petAge','$petWeight','$ownerID')"; $result = mysql_query($createQuery2); //preforming mysql $createQuery2 //displaying message to let user know the task has been carryed out and the patient has been added echo ("Thank you<p>Your new patient has been added successfully.<p>"); echo("<a href='index.php'><font color='blue'>Return to home page</font></a>"); } else ?> Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted April 11, 2008 Share Posted April 11, 2008 You can use output buffering to stop the html being sent before the header. http://uk.php.net/manual/en/function.ob-start.php 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.