7 Replies - 432 Views - Last Post: 20 July 2012 - 08:57 AM Rate Topic: -----

#1 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 343
  • Joined: 14-February 11

Redirect + send email

Posted 19 July 2012 - 03:35 PM

Hi there.

So, I want to redirect a page after send the email, however, this redirect should have parameters in the url (id=1 or 2 or 3).

function getMarc() {
    return $_GET['id'];
}


This code gets the id.

Then, first I've to check if there's empty fields and after that redirect the page according to the url.
However, this is not redirecting and is sending me a email even if the fields are empty, and shouldn't!

if (empty($name) || empty($marc) || empty($phone) || empty($model) ||
        empty($email)) {
    echo "<script type='text/javascript'>window.alert('Please do not leave empty fields')</script>";
    echo "<script type='text/javascript'>window.location='main.php?id=" . getMarc() . "' </script>";

} else {

    if ($send_contact) {
        echo "<script type='text/javascript'>window.alert('Message sended.')</script>";
        echo "<script type='text/javascript'>window.location='main.php?id=" . getMarc() . "'</script>";
    } else {
        echo "<script type='text/javascript'>window.alert('Error sending.')</script>";
         echo "<script type='text/javascript'>window.location='main.php?id=" . getMarc() . "'</script>";
    }
}


What could be wrong? Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Redirect + send email

#2 exiles.prx  Icon User is offline

  • D.I.C Head

Reputation: 65
  • View blog
  • Posts: 239
  • Joined: 22-November 10

Re: Redirect + send email

Posted 19 July 2012 - 04:34 PM

Your redirecting the page, but your PHP will continue to execute unless you use die() or exit() after the redirect.Also, why are you using javascript to redirect rather then using PHP's header function?

This post has been edited by exiles.prx: 19 July 2012 - 04:48 PM

Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3521
  • View blog
  • Posts: 10,161
  • Joined: 08-June 10

Re: Redirect + send email

Posted 19 July 2012 - 10:21 PM

View Postexiles.prx, on 20 July 2012 - 01:34 AM, said:

Also, why are you using javascript to redirect rather then using PHP's header function?

one could go even further and ask: why redirect when you can include the next page’s content?
Was This Post Helpful? 2
  • +
  • -

#4 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 343
  • Joined: 14-February 11

Re: Redirect + send email

Posted 20 July 2012 - 06:08 AM

View Postexiles.prx, on 19 July 2012 - 04:34 PM, said:

Your redirecting the page, but your PHP will continue to execute unless you use die() or exit() after the redirect.Also, why are you using javascript to redirect rather then using PHP's header function?

I already used die() and exit() and didn't work.
I'm using Javascript because I do some output before redirect, so I'll not be able to redirect if I use that function.

View PostDormilich, on 19 July 2012 - 10:21 PM, said:

one could go even further and ask: why redirect when you can include the next page’s content?

I didn't understand.

This post has been edited by Keylogger: 20 July 2012 - 06:08 AM

Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3521
  • View blog
  • Posts: 10,161
  • Joined: 08-June 10

Re: Redirect + send email

Posted 20 July 2012 - 06:37 AM

View PostKeylogger, on 20 July 2012 - 03:08 PM, said:

View PostDormilich, on 19 July 2012 - 10:21 PM, said:

one could go even further and ask: why redirect when you can include the next page’s content?

I didn't understand.

compare the following:
<?php // file1.php
// needs one round-trip to the client
header("Location: file2.php");
?>

vs.
<?php // file1.php
// serves data directly
include "file2.php";
?>

Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2927
  • View blog
  • Posts: 10,114
  • Joined: 08-August 08

Re: Redirect + send email

Posted 20 July 2012 - 06:42 AM

View PostKeylogger, on 20 July 2012 - 09:08 AM, said:

I didn't understand.

Two ways of getting the appropriate page to the browser:
<?php
if($something == true) {
	// Redirect:
	// This sends a message back to the browser telling it to request a new page.
	// If the new page is on the same server that this script is running on, that's a waste of bandwidth:
	// Browser requests a page ===> Server receives request and runs script.
	// Script decides to redirect ===> sends message back to browser.
	// Browser receives message ===> sends message requesting a new page.
}

if($something == true) {
	// Send a different page back to browser by using include() or require().
}

The latter is simpler, faster, and more reliable.
Was This Post Helpful? 0
  • +
  • -

#7 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 343
  • Joined: 14-February 11

Re: Redirect + send email

Posted 20 July 2012 - 07:21 AM

This is now redirecting, it was a "'" that was missing, however, even if the fields are empty it's sending also the email, and should not send the email if the fields are empty.

I tried with Die() and didn't work.


if (empty($name) || empty($marc) || empty($phone) || empty($model) ||
        empty($email)) {
    echo "<script type='text/javascript'>window.alert('Please do not leave empty fields')</script>";
    echo "<script type='text/javascript'>window.location='main.php?id=" . getMarc() . "' </script>";
    die(); // should stop here and not send the email.
} else {
    // rest of the code is up.
}

This post has been edited by Keylogger: 20 July 2012 - 07:22 AM

Was This Post Helpful? 0
  • +
  • -

#8 Keylogger  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 343
  • Joined: 14-February 11

Re: Redirect + send email

Posted 20 July 2012 - 08:57 AM

Solved. I was using or (||) and I need and (&&).

Thanks everyone.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1