poleman Posted February 8, 2007 Share Posted February 8, 2007 Hi there, I'm trying to redirect to a url once someone has entered their details into a form. current code is : <?php $con = mysql_connect ("*********","********","******"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("********", $con);$sql="INSERT INTO phpbb_users(username, user_email) VALUES ('$_POST[name]','$_POST[useremail]')";if (!mysql_query ($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added";mysql_close($con) ?> I kn ow I've got to change the '1 record added' part of the code but not sure what to put. Any text i put there will just bring it up int he browser. So how do i get it to redirect to an entirely different url? Hope someone can help Thanks!! Rich Link to comment https://forums.phpfreaks.com/topic/37645-redirecting-from-php-code/ Share on other sites More sharing options...
nloding Posted February 8, 2007 Share Posted February 8, 2007 <?php $con = mysql_connect ("*********","********","******"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("********", $con);$sql="INSERT INTO phpbb_users(username, user_email) VALUES ('$_POST[name]','$_POST[useremail]')";if (!mysql_query ($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); header('Location: whatever.php'); ?> Just use header('Location: whatever.php'); but it has to be used before anything hits the browser. Link to comment https://forums.phpfreaks.com/topic/37645-redirecting-from-php-code/#findComment-180104 Share on other sites More sharing options...
poleman Posted February 8, 2007 Author Share Posted February 8, 2007 what do you mean, it has to be used before ianything hits the browser? if i type in mysite name home page - www.jsay.co.uk.php, will that work? My site is in html, not php. Also, now I get this error message when trying to sign up to the newsletter: Error: Duplicate entry '0' for key 1 I don't think I've changed anything on the php file so why is it showing this? How can I fix it? Thanks!! Link to comment https://forums.phpfreaks.com/topic/37645-redirecting-from-php-code/#findComment-180110 Share on other sites More sharing options...
nloding Posted February 9, 2007 Share Posted February 9, 2007 The header has to be sent before any HTML or anything is displayed in the browser. Everything between <?php and ?> tags is done on the server end, not on the client end. You can't type in "www.jsay.co.uk.php" but you can type "http://www.jsay.co.uk/" ... it's just a path to something, doesn't have to be a website or an individual file ... you choice. I believe that error is because you're duplicating content in your database ... could be wrong though. Link to comment https://forums.phpfreaks.com/topic/37645-redirecting-from-php-code/#findComment-180319 Share on other sites More sharing options...
artacus Posted February 9, 2007 Share Posted February 9, 2007 My site is in html, not php. Thats funny, they sure look like php tags to me. You can do it with <script>document.location.href = 'goAway.htm';</script> Link to comment https://forums.phpfreaks.com/topic/37645-redirecting-from-php-code/#findComment-180323 Share on other sites More sharing options...
neo777ph Posted February 9, 2007 Share Posted February 9, 2007 I used header('Location: whatever.php') when redirecting to pages..However the limitation on using this is that you should declare it on the first line of your code.. That would not be cool.. I got a solution: declare this tag on first line of your code.. <?php ob_start(); ?> Doing so..you could use header('Location: whatever.php') Function on whatever part of your code. FOR EXAMPLE : <? php ob_start(); ......MY CODE.. if($numrows != 0) { header("LOCATION: http://www.yahoo.com"); } else { header("LOCATION: http://www.google.com"); } ?> Hope i helped you.. <?php ob_start(); ?> is used to cache header info. Link to comment https://forums.phpfreaks.com/topic/37645-redirecting-from-php-code/#findComment-180467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.