Hi,
First of all, sorry for my English, it's not my primary language and I don't know a lot of coding related terms.
I have a weird problem: a page from my website keeps loading twice in certain condition.
Here's how it's supposed to work:
1.) POST data are sent from another page to "test.php?cat=let3". If the user come from the first page (which sent the $_POST data), the page is supposed to process the actions written inside the "if" condition which "echo"s a link "test.php?cat=let3&conf=X" where X is an id stored by one of the actions located in the "if" condition.
2.) When the user clicks on the link "test.php?cat=let3&conf=X", he's supposed to be redirected on the same PHP page which should process other actions since my POST data aren't there anymore but are somewhat replace by GET data (which I check with a "elseif" following the "if" from point 1).
The problem is that once "test.php?cat=let3&conf=X" is clicked, the "elseif" condition is loaded twice (the whole page is but the conditions redirect to this particular part). But, if I don't follow the usual path using my form to send POST data and that I manually enter "test.php?cat=let3&conf=X" in my URL bar (where X is an id I manually set the value to 0 in my database), it works fine and loads once only.
Here's the code for the page that include the one that causes problem:
<?php
session_start();
$mysqlcon = mysql_connect("localhost", "root", "");
mysql_select_db("test");
if($_GET['cat'] == 'let3')
{
include("newsmail.php");
}
?>
And here's the code for the page loading twice while following the path where I send POST data (there's a few "echo"s in I use to see how many times it loads):
<?php
if(!empty($_POST))
{
mysql_query("INSERT INTO newsindex VALUES('','test','0',SYSDATE())");
$lastid = mysql_insert_id();
echo '<a href="test.php?cat=let3&conf='.$lastid.'">Valider</a>';
echo $_SESSION['count'].' - if';
}
elseif(isset($_GET['conf']))
{
$_SESSION['count']++;
echo $_SESSION['count'].' - elseif';
$idn = mysql_real_escape_string(htmlspecialchars($_GET['conf']));
$idnvraw = mysql_query("SELECT * FROM newsindex WHERE id = '$idn' AND exp = '0'");
if(mysql_num_rows($idnvraw) != FALSE)
{
mysql_query("UPDATE newsindex SET exp = '1' WHERE id = '$idn'");
echo 'Everything's okay';
}
else
{
echo $_SESSION['count'].' - elseif';
}
}
else
{
echo $_SESSION['count'].' - else';
}
?>
The database is correctly written/read, the only problem is that weird reloading problem.
Just in case it could be useful,here's the database table I use: "id" (INT / 11 / auto_increment), "lien" (VARCHAR / 36), "exp" (INT / 1) and "date" (DATE).
Thanks in advance for any help