Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,181 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,137 people online right now. Registration is fast and FREE... Join Now!




php/mysql simple form redirection

2 Pages V  1 2 >  
Reply to this topicStart new topic

php/mysql simple form redirection

irishgirl
25 Aug, 2008 - 02:48 AM
Post #1

D.I.C Head
**

Joined: 22 Aug, 2008
Posts: 68


My Contributions
CODE

<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<input type="hidden" name="step" value="1">


CODE

if ($step == "1"){
$to = "$temail";
$name= $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$subject = "Booking from $name <$email>";
$address = $_REQUEST['address'];
$date = $_REQUEST['date'];
$time = $_REQUEST['time'];
$comments = $_REQUEST['comments'];
$message = "Hi,

You have received a booking from $name.";

$headers = "From: $name <$email>";
$sent = mail($to, $subject, $message, $headers);
Header("Location: ./thankyou.html");
}
?>


However it will not redirect to thankyou.html
If I put thankyou.html as the action,it then shows up but the email does not send. If i put a hidden input field for redirection that also doesn't work. Any help would be hugely appreciated, thanks!

This post has been edited by irishgirl: 25 Aug, 2008 - 02:49 AM
User is offlineProfile CardPM
+Quote Post

pemcconnell
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 02:51 AM
Post #2

D.I.C Regular
Group Icon

Joined: 5 Aug, 2008
Posts: 403



Thanked: 38 times
Dream Kudos: 75
My Contributions
your header has a capital 'H' - make this a lowercase 'h'

i.e.

header('Location:thankyou.html');
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 02:51 AM
Post #3

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 326



Thanked: 12 times
Dream Kudos: 250
My Contributions
php
if ($_POST['step'] == 1) { ... }

User is offlineProfile CardPM
+Quote Post

irishgirl
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 02:55 AM
Post #4

D.I.C Head
**

Joined: 22 Aug, 2008
Posts: 68


My Contributions
Thanks guys, I made these changes but still won't redirect sad.gif
User is offlineProfile CardPM
+Quote Post

pemcconnell
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 02:55 AM
Post #5

D.I.C Regular
Group Icon

Joined: 5 Aug, 2008
Posts: 403



Thanked: 38 times
Dream Kudos: 75
My Contributions
also $temail doesn't seem to be set
User is offlineProfile CardPM
+Quote Post

irishgirl
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 02:58 AM
Post #6

D.I.C Head
**

Joined: 22 Aug, 2008
Posts: 68


My Contributions
it is, just further up the page, didnt feel i had to post the code for that as working fine
User is offlineProfile CardPM
+Quote Post

pemcconnell
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 03:00 AM
Post #7

D.I.C Regular
Group Icon

Joined: 5 Aug, 2008
Posts: 403



Thanked: 38 times
Dream Kudos: 75
My Contributions
could you post the whole page and I'll take a look
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 03:03 AM
Post #8

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 326



Thanked: 12 times
Dream Kudos: 250
My Contributions
I cut a little bit the code to test and works fine :

php

<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="submit" />
</form>
<?php

if ($_POST['step'] == "1"){
Header("Location: page.html");
}

?>


This post has been edited by MitkOK: 25 Aug, 2008 - 03:05 AM
User is offlineProfile CardPM
+Quote Post

irishgirl
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 03:03 AM
Post #9

D.I.C Head
**

Joined: 22 Aug, 2008
Posts: 68


My Contributions
CODE

<?
include('inc/header.php');
require("admin/conf.php");
mysql_connect("$DBHost","$DBUser","$DBPass");
$request = explode("/",$_SERVER["REQUEST_URI"]);
$pagename = $request[1];
$tid=$_GET['id'];
$catname=$_GET['name'];
?>

<div class="main-box">
<div class="main-box-1">
<?php $result=mysql("$DBName","SELECT * FROM category WHERE name = '$catname'");
while($row=mysql_fetch_row($result)) {
$id=$row[0];
$catname = $row[1];
}

?>

<h2><?php echo"<img src=\"images/cat_images/$id-2.jpg\" width=\"138\" height=\"29\" alt=\"\" title=\"\" class=\"png\" />"; ?></h2>
<h3><img src="images/txt_profile.png" width="54" height="11" alt="Profile" title="" class="png" /></h3>

<?php $result2=mysql("$DBName","SELECT * FROM profile WHERE id = '$id'");
while($row2=mysql_fetch_row($result2)) {
$id = $row2[0];
$tname = $row2[1];
$tsynopsis = $row2[3];
$tdetails = $row2[4];
$temail= $row2[5];
$tphone= $row2[6];
$taddress = $row2[7];
}

?>

<?php echo"<img src=\"images/profile_images/main/$id-1.jpg\" width=\"119\" height=\"119\" alt=\"\" class=\"bord-1-left\" />";?>



    <h3><?php echo "$tname - $catname Profile"; ?></h3>

<p class="nopadbotm"><?php echo "$tsynopsis"; ?><br /><br/>
<ul class="var-1">
<?php echo "$tdetails"; ?> <br/><br/>
    </ul>
                <p class="nopadbotm"><img src="images/icon_phone.gif" width="29" height="29" alt="" class="valmid" /> To contact <?echo "$tname";?>, please call on : <span class="style-1"><?echo "$tphone";?></span>.</p>
                <div class="separ-line-1">
                    <!---->
                </div>
            <div class="formfield-1">
                            <h3><img src="images/txt_book-appointment.png" width="139" height="11" alt="Book Appointment" title="" class="png" /></h3>
                            <form method="post" action="<?php $_SERVER['PHP_SELF']?>">
                            <input type="hidden" name="step" value="1">
                            <table>
                            <tr>
                            <td>Full Name:</td>
                            <td><input name="name" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Email:</td>
                            <td><input name="email" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Phone:</td>
                            <td><input name="phone" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Address:</td>
                            <td><input name="address" type="text" size="51"></td>
                            </tr>
                            <tr>
                            <td> Preferred date of appointment:</td>
                            <td><input name="date" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td> Preferred time of appointment:</td>
                            <td><input name="time" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Comments:</td>
                            <td ><textarea rows="7" name="comments" cols="43"></textarea></td>
                            </tr>
                            <tr>
                                            <td></td>
                                            <td>                    <p class="submit-btn">
                                                    <input type="image" src="images/btn_book-now.png" class="btn png" />
                                                </p></td>
                </tr>
                            </table>


                            </form>
                </div>
            </div>
        </div>
        <!--main-box-->
<?
include('inc/footer.php');
if ($_POST['step'] == 1){
$to = "$temail";
$name= $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$subject = "Booking from $name <$email>";
$address = $_REQUEST['address'];
$date = $_REQUEST['date'];
$time = $_REQUEST['time'];
$comments = $_REQUEST['comments'];
$message = "Hi,

You have received a booking from $name. ";

$headers = "From: $name <$email>";
$sent = mail($to, $subject, $message, $headers);
header("Location: ./thankyou.html");
}
?>

User is offlineProfile CardPM
+Quote Post

pemcconnell
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 03:13 AM
Post #10

D.I.C Regular
Group Icon

Joined: 5 Aug, 2008
Posts: 403



Thanked: 38 times
Dream Kudos: 75
My Contributions
change the 2nd last line ($sent = mail(....)) to this:

CODE

if(mail($to, $subject, $message, $headers)){
        header("Location: ./thankyou.html");
    }else{
        echo 'ERROR: '.$to.', '.$subject.', '.$message.', '.$headers;
    }


and see what is getting passed through to the mail function.

Is there any errors at all or is this page just turning blank?
User is offlineProfile CardPM
+Quote Post

irishgirl
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 03:17 AM
Post #11

D.I.C Head
**

Joined: 22 Aug, 2008
Posts: 68


My Contributions
QUOTE(pemcconnell @ 25 Aug, 2008 - 04:13 AM) *

change the 2nd last line ($sent = mail(....)) to this:

CODE

if(mail($to, $subject, $message, $headers)){
        header("Location: ./thankyou.html");
    }else{
        echo 'ERROR: '.$to.', '.$subject.', '.$message.', '.$headers;
    }


and see what is getting passed through to the mail function.

Is there any errors at all or is this page just turning blank?



I tried that but it's still the same sad.gif The actual page just reloads but when I check my email inbox the email has delivered so everything is working fine except for redirecting.
User is offlineProfile CardPM
+Quote Post

pemcconnell
RE: Php/mysql Simple Form Redirection
25 Aug, 2008 - 03:38 AM
Post #12

D.I.C Regular
Group Icon

Joined: 5 Aug, 2008
Posts: 403



Thanked: 38 times
Dream Kudos: 75
My Contributions
Move the include('inc/footer.php'); to the last line - if there is an error its probibly not showing on screen but will on the 'view source'.

I would move the whole if($_POST['setp']==1){ to the very top of your script and make sure there are no extra spaces. having an extra space anywhere in the code before a header() can break it - however you normally get an error.

Try it anyway, if nothing else, it'll improve your code layout and flow

CODE

<?php
if ($_POST['step'] == 1){
    $to = "myemail@domain.com";
    $name= $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $phone = $_REQUEST['phone'];
    $subject = "Booking from $name <$email>";
    $address = $_REQUEST['address'];
    $date = $_REQUEST['date'];
    $time = $_REQUEST['time'];
    $comments = $_REQUEST['comments'];
    $message = "Hi,    you have received a booking from $name. ";
    
    $headers = "From: $name <$email>";
    
    if(mail($to, $subject, $message, $headers)){
        header("Location: ./thankyou.html");
    }else{
        echo 'ERROR: '.$to.', '.$subject.', '.$message.', '.$headers;
                die();
    }

}
include('inc/header.php');
require("admin/conf.php");
mysql_connect("$DBHost","$DBUser","$DBPass");
$request = explode("/",$_SERVER["REQUEST_URI"]);
$pagename = $request[1];
$tid=$_GET['id'];
$catname=$_GET['name'];
?>

<div class="main-box">
<div class="main-box-1">
<?php $result=mysql("$DBName","SELECT * FROM category WHERE name = '$catname'");
while($row=mysql_fetch_row($result)) {
$id=$row[0];
$catname = $row[1];
}

?>

<h2><?php echo"<img src=\"images/cat_images/$id-2.jpg\" width=\"138\" height=\"29\" alt=\"\" title=\"\" class=\"png\" />"; ?></h2>
<h3><img src="images/txt_profile.png" width="54" height="11" alt="Profile" title="" class="png" /></h3>

<?php $result2=mysql("$DBName","SELECT * FROM profile WHERE id = '$id'");
while($row2=mysql_fetch_row($result2)) {
$id = $row2[0];
$tname = $row2[1];
$tsynopsis = $row2[3];
$tdetails = $row2[4];
$temail= $row2[5];
$tphone= $row2[6];
$taddress = $row2[7];
}

?>

<?php echo"<img src=\"images/profile_images/main/$id-1.jpg\" width=\"119\" height=\"119\" alt=\"\" class=\"bord-1-left\" />";?>



    <h3><?php echo "$tname - $catname Profile"; ?></h3>

<p class="nopadbotm"><?php echo "$tsynopsis"; ?><br /><br/>
<ul class="var-1">
<?php echo "$tdetails"; ?> <br/><br/>
    </ul>
                <p class="nopadbotm"><img src="images/icon_phone.gif" width="29" height="29" alt="" class="valmid" /> To contact <?echo "$tname";?>, please call on : <span class="style-1"><?echo "$tphone";?></span>.</p>
                <div class="separ-line-1">
                    <!---->
                </div>
            <div class="formfield-1">
                            <h3><img src="images/txt_book-appointment.png" width="139" height="11" alt="Book Appointment" title="" class="png" /></h3>
                            <form method="post" action="<?php $_SERVER['PHP_SELF']?>">
                            <input type="hidden" name="step" value="1">
                            <table>
                            <tr>
                            <td>Full Name:</td>
                            <td><input name="name" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Email:</td>
                            <td><input name="email" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Phone:</td>
                            <td><input name="phone" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Address:</td>
                            <td><input name="address" type="text" size="51"></td>
                            </tr>
                            <tr>
                            <td> Preferred date of appointment:</td>
                            <td><input name="date" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td> Preferred time of appointment:</td>
                            <td><input name="time" type="text" size="24"></td>
                            </tr>
                            <tr>
                            <td>Comments:</td>
                            <td ><textarea rows="7" name="comments" cols="43"></textarea></td>
                            </tr>
                            <tr>
                                            <td></td>
                                            <td>                    <p class="submit-btn">
                                                    <input type="image" src="images/btn_book-now.png" class="btn png" />
                                                </p></td>
                </tr>
                            </table>


                            </form>
                </div>
            </div>
        </div>
        <!--main-box-->
<?php
include('inc/footer.php');
?>


If that doesnt work i'd use a javascript redirect that triggers on the body onload <- not ideal but will do until you figure out the PHP prob

This post has been edited by pemcconnell: 25 Aug, 2008 - 03:46 AM
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:49AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter