Reputation: 435
I'm tring to use php header. I look up to php header manual. In my case I think I should use header("Location: $_SERVER[PHP_SELF]");
But when I refreshed my page I got an error " The page isn’t redirecting properly".
My HTML code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class=CSSTableGenerator>
<table>
<thead>
<tr>
<th>ID</th>
<th>Code</th>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
require ("upName.php");
for($i = 1; $i <= $usr; $i++)
{
echo"<form action='?' method='POST'>";
echo"<tr>";
echo"<td><div id='id'>".$id[$i]."</div></td>";
echo"<td><div id='code'><input type='hidden' name='id' value='" . $id[$i] . "|".$id[$i]."' />".$code[$i]."</div></td>";
echo"<td><div id='name'><input id='name' name='name' value='$name[$i]' /></div></td>";
echo"<td><input type='submit' id='muuda' value='Muuda' /></td>";
echo"</tr>";
echo"</form>";
}
?>
<script>
</script>
</tbody>
</table>
</div>
</body>
</html>
My PHP
<?php
$usr=0;
$sql="SELECT * from user where code like '%IN%' ";
$sensors = $db->query($sql);
$result1=$sensors->fetchAll(PDO::FETCH_ASSOC);
$namee=$_POST['name'];
$codee=$_POST['code'];
$idd=explode('|', $_POST['id']);
$idd1=trim($idd[0]);
$idd2=trim($idd[1]);
$idd2=$idd2+1;
if(empty($_POST['name'])){}else{
$sql2="UPDATE user set name='" .$namee. "' where id IN('" .$idd1. "','".$idd2."') ";
if(isset($_SESSION['name'])) {
$sensorss = $db->query($sql2);
$result2=$sensors->fetchAll(PDO::FETCH_ASSOC);}}
header("Location: $_SERVER[PHP_SELF]");
//Debug::dump($sql2);
foreach ($result1 as $row)
{
$usr++;
$id[$usr]= $row["id"];
$code[$usr]= $row["code"];
$name[$usr]= $row["name"];
$code[$usr]=explode(' ', $code[$usr]);
$code[$usr]=trim($code[$usr][0]);
}
?>
Cant figure out whats the problem..
Upvotes: 0
Views: 2605
Reputation: 184
Try using this code:
header("Location: ".$_SERVER['PHP_SELF']." ");
Upvotes: 2
Reputation: 3990
The thing is that you are redirecting to the same page. That creates a redirection loop, which generates the error your are getting.
Upvotes: 0