Jump to content

problem with code


haroon

Recommended Posts

Hello Guys. i am new to php. header redirection are not working with my current form. please have a look @ my code and suggest me some tips thnx.

 

<?

session_start();

include_once("Database.php");

$db=new Database;

if (isset($to_del))

{

foreach ($to_del as $v)

{

//echo"$v";

$sql="delete from e_post where id='$v'";

$db->insert($sql);

  header("location: inbox.php");

}

}

else

{

  header("location: inbox.php?Err=1");

 

}

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/53962-problem-with-code/
Share on other sites

Try moving the header redirect after the for loop. If its in the for loop PHP will only run once through the loop. You will want to move the header redirect after the loop in order for the loop to run more the once. New code:

<?php

session_start();

include_once 'Database.php';

$db = new Database;

if (isset($to_del))
{
    foreach ($to_del as $v)
    {
        //echo"$v";

        $sql="DELETE FROM e_post WHERE id='$v'";
        $db->insert($sql);
    }

    header("location: inbox.php");
}
else
{
  header("location: inbox.php?Err=1");

}

?>

If it still doesn't work could you describe what sort of output you are getting? If its a blank page then add the following at the top of your script before session_start():

error_reporting(E_ALL);
ini_set('display_errors', 'On');

 

Do you get any output now? Post any output you get here.

 

 

Also could you tell me where the variable $to_del comes from too?

Link to comment
https://forums.phpfreaks.com/topic/53962-problem-with-code/#findComment-266808
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.