Jump to content

[SOLVED] it's not redirecting if !$_POST, any suggestions?


Recommended Posts


<?php
error_reporting(E_ALL & E_NOTICE);

echo '<html dir="ltr">

<head>

<title>Site</title>
</head>

<body bgcolor="#ECD9C6">
<table align="center" width="777" height="700">
<tr>
<td background="bg_e.jpg">

<p> </p>
<p> </p>
<table height="40" width="777">
<tr>
<th>

<font face="Arial" size="5" color="#EDD5C3"> page3 </font></th>
</tr>
</table>


<table height="630" width="777">
<tr>
<td>';

if(!$_POST)
{
header('Location: insert.php') or die();
}
else
{
require_once('config.php');

$insert = "INSERT INTO samoi (event, date) VALUES ('$event', '$date')";
$insertSQL = mysql_query($insert) or die(mysql_error());

echo 'The new event has been submitted <br>
 hit <a href="index.php"> this link </a> to view them';
}

function clean($str)
{
return mysql_escape_string($str);
}

?>

 

it's not redirecting !!

 

How can I get the error?

1) You should be using

 

if(!isset($_POST['your_name']))

 

Not:

 

if(!$_POST)

 

 

2) To turn error reporting temporarily on put this at the top of your script.

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

If anything is echo'd to the screen the header function cannot work.

 

I would suggest replacing this:

 

header('Location: insert.php') or die();

 

with

 

echo '<script>location.href = "insert.php"</script>';

 

Will give you the same result without having to re-do your current code. Although I would suggest outputting everything at the end by storing the output into a string, instead of just echo'ing it out. But yea.

1) You should be using

 

if(!isset($_POST['your_name']))

 

Not:

 

if(!$_POST)

 

 

2) To turn error reporting temporarily on put this at the top of your script.

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

Ok, I have two questions,

 

1 - I have the page insert.php and it has a form with a submit button under the name="submitBTN", is it the name that I put in this

!isset($_POST['submitBTN']) 

if it is, then I have tried it and it didn't work !

 

2 - I'm sorry, but I feel curies, this

 ini_set ("display_errors", "1"); 

is not the same as in the php.ini file? it's set to On already.

 

 

Thank you in advance

If anything is echo'd to the screen the header function cannot work.

 

I would suggest replacing this:

 

header('Location: insert.php') or die();

 

with

 

echo '<script>location.href = "insert.php"</script>';

 

Will give you the same result without having to re-do your current code. Although I would suggest outputting everything at the end by storing the output into a string, instead of just echo'ing it out. But yea.

 

Wow, very rich info.

 

I will try it, and will come back ! :)

Ok, I have two questions,

 

1 - I have the page insert.php and it has a form with a submit button under the name="submitBTN", is it the name that I put in this

!isset($_POST['submitBTN']) 

if it is, then I have tried it and it didn't work !

 

2 - I'm sorry, but I feel curies, this

 ini_set ("display_errors", "1"); 

is not the same as in the php.ini file? it's set to On already.

 

 

Thank you in advance

 

1. Yes it is the name you put in there.

 

2. The only error I would see is calling the header function after you have echo'd text to the screen. As I mentioned above that is not kosher. Also check that you are using "POST" variables and not "GET" in your form.

 

As for the errors, if display_errors is set in the php.ini to on, yes that means it is on but this can be overwritten by .htaccess so it is good practice when debugging to add that to the top just in case.

If anything is echo'd to the screen the header function cannot work.

 

I would suggest replacing this:

 

header('Location: insert.php') or die();

 

 

 

 

echo '<script>location.href = "insert.php"</script>';

 

Will give you the same result without having to re-do your current code. Although I would suggest outputting everything at the end by storing the output into a string, instead of just echo'ing it out. But yea.

 

Wow, very rich info.

 

I will try it, and will come back ! :)

 

It works ! :)

 

Thank you.

 

But do you think that it will be a good protection? since the redirecting is a java script?

 

what if I have a firefox, and have the addon web devoloper toolbar, and I disabled the java script from the tool bar, I'll still get the same result I came with, right?

Ok, I have two questions,

 

1 - I have the page insert.php and it has a form with a submit button under the name="submitBTN", is it the name that I put in this

!isset($_POST['submitBTN']) 

if it is, then I have tried it and it didn't work !

 

2 - I'm sorry, but I feel curies, this

 ini_set ("display_errors", "1"); 

is not the same as in the php.ini file? it's set to On already.

 

 

Thank you in advance

 

1. Yes it is the name you put in there.

 

2. The only error I would see is calling the header function after you have echo'd text to the screen. As I mentioned above that is not kosher. Also check that you are using "POST" variables and not "GET" in your form.

 

As for the errors, if display_errors is set in the php.ini to on, yes that means it is on but this can be overwritten by .htaccess so it is good practice when debugging to add that to the top just in case.

 

Yes it works as maq taught me :)

If javascript is disabled that will not work, since it does use javascript.

 

To use the header function you need to call that before anything is output to the screen, so do that if check at the top of the page and it should work.

If javascript is disabled that will not work, since it does use javascript.

 

To use the header function you need to call that before anything is output to the screen, so do that if check at the top of the page and it should work.

wow man, you're very helpful and quick responder :) Thank you very much.

 

I'll give it a shot and come back !

If javascript is disabled that will not work, since it does use javascript.

 

To use the header function you need to call that before anything is output to the screen, so do that if check at the top of the page and it should work.

 

I really wish to be your friend :)

 

Maaaaan You're professional.

 

I appreciate it, it works just fine with your help.

 

You know what makes me sad right now? that I have read php books and I still don't recall some information form what I have read !

 

But thank you :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.