Topic: Problem with page redirecting: header("Location: $url");

Hello everybody,

This is a warning i've got whenever I use "header("Location: $url"); ".

Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\index.php:15) in C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\user_manager.php on line 319

Is there any solution to redirect to a url without using "header("Location: $url"); Or somehow I can fix the above problem?

I've been reading some topics on some websites, and they are all about how to use header("Location: $url"); but i haven't found any right answer for my situation.

Note: "header("Location: $url");" runs ok on localhost at my computer,  I only got this problem when I upload my project to a hosting.

Thank a lot for helping me!
Quyen,

Last edited by quyen (2009-11-04 09:19:14)

Re: Problem with page redirecting: header("Location: $url");

This may help.
http://forum.mamboserver.com/showthread.php?t=49427

Also
http://www.tech-recipes.com/rx/1489/sol … eady-sent/
"3) Make sure there is no white space outside of the php start and end tags. While a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line. This is a common culprit." although some of my files have a blank space and still work.

Another reason is stated here:-
http://www.kirupa.com/forum/showthread.php?t=265403
"You're trying to modify header information after it's already sent to the browser. You need to move the PHP code that's trying to do this to the top of the page, above everything else, even a blank space."

Last edited by Wickham (2009-11-04 09:52:35)

Re: Problem with page redirecting: header("Location: $url");

Thanks for you reply,

I might have look at those links, and try to fix my problems. By the way, Do you know somehow we can redirect to a page without using header("Location: $url") ?.

In my case: I want to show a message before redirect to any pages?

Thank you very much for that.
Quyen,

Re: Problem with page redirecting: header("Location: $url");

Probably by putting in an echo statement just before the header like

echo "Thank You";
header("Location: $url");

Re: Problem with page redirecting: header("Location: $url");

Well, I've tried that before but when you use headers to show a message before redirect to a page, actually you cannot see the message, the headers will execute straight away.
Anyway thanks a lot !
Quyen,

Re: Problem with page redirecting: header("Location: $url");

quyen wrote:

Well, I've tried that before but when you use headers to show a message before redirect to a page, actually you cannot see the message, the headers will execute straight away.

Yes, I suppose that's obvious and I should have thought of that !

It would be seen
1) if the header url didn't work
2) if you add in a delay to the header url function.

Re: Problem with page redirecting: header("Location: $url");

It is also possible to do this with Javascript and a time delay:
http://www.tizag.com/javascriptT/javascriptredirect.php

(Though if Javascript is turned off, this obviously won't work.)

Re: Problem with page redirecting: header("Location: $url");

Here's the same thing in PHP, using header('refresh: '):
http://www.desilva.biz/php/phprefresh.html

Re: Problem with page redirecting: header("Location: $url");

Thanks a lot Wickham and falkencreative, I am sure I can solve my problems soon. Thanks again.

Quyen,

Re: Problem with page redirecting: header("Location: $url");

I am not sure if this has been solved yet, but http://webdesign.about.com/od/metatagli … 80300a.htm may be of some assistance. After you understand how to use the meta tag you can then echo it to effectively redirect.

Ex. "   echo "<meta http-equiv="refresh" content="2;url=http://example.com">";   "
This will refresh the page at the new location ("http://example.com") in 2 seconds.

"http-equiv="refresh" " Is some what self explanatory, it will cause a refresh but if there is a url value in 'content' then it will refresh with a new location.

" content="2;url=http://example.com" " ' content="2 ' is where you can set the amount of time (in seconds) that the browser will wait before refreshing. ' url=http://example.com ' is where it will go upon refreshing.

It has proven a worthy alternative for me when  "header("location: ")" redirecting just doesn't seem to fit.

Hope it helps you out.

-Adam

Last edited by adamlen (2009-11-12 07:00:45)

Re: Problem with page redirecting: header("Location: $url");

I've been trying to solve my problem by using http://www.desilva.biz/php/phprefresh.html and http://www.tizag.com/javascriptT/javasc … irect.php, but I haven't solved my problems yet, I will try some other solutions, but I am still looking for someone to help me. I know "Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\index.php:15) in C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\user_manager.php on line 319" is just a warning, not an error, but the thing is I don't want this warning to show up on the page, and whenever this warning is occurs, it stops redirecting. I will try to use Adam's solution and see what'll happen....

Thank you very much Adam,
Quyen,

Re: Problem with page redirecting: header("Location: $url");

if l wll be you, l will use a javascript.

define something like
$ready=<a href ='url'</a>;


then use javascript code  and refer the $ready in the javascript.

It is very easy. If you can not handle it, let me know and l will post you a full written java script code!


However, your warning seems like you have two

if(isset($_POST['xxxx'])) {
            header("Location: url");


if this is the case, do well to delete one since the error message is telling you that, the header has already sent a location and you are trying to overwrite on the older one....





"Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\index.php:15) in C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\user_manager.php on line 319"

check the line 319 of the user_mnager.php and the line 15 of the index.php. There is a conflict......>the index.php header you are trying to write has already been sent by the user_manager.php. And l bet you have included one of them in the other.


Best Regards

Re: Problem with page redirecting: header("Location: $url");

Thanks for your reply,

Yeah you're right, I've used Header(); quite a lot in my php pages, ofcourse I used it for different purposes, I've been trying to comment all the //Headers, and use print "somthing"; to replaces Header commands, it works fine, but Whenever I remove one of the comment lines, the warning will appear straight away.

I am sure I did something wrong, but I haven't found it yet. Maybe I already used Header in the file which is required in the php page. But I think you can use multiple Headers command on the same page or include or require, right?

Thanks a lot for your help but really I don't want to use javascript in this case, because  users can turn it off anytime, that means my website won't work ok without JS

Quyen,

Re: Problem with page redirecting: header("Location: $url");

sure you can use header as many times as you want so far as they are in an

IF(){

yourcode
header('')
}elseif(){
yourcode 2
header('')

}
elseif(){
yourcode 3
header('')

}

same as for
Foreach(){} ect and also in a function myFunction(){}

Making sure none of the gloabal variables concides with another.

Re: Problem with page redirecting: header("Location: $url");

Yeah this is my php code: it may show you something easy to understand.

                case 'formAdd':
                    require_once("menu_adding_form.php");
                break;
                case 'add':
                    $type = $_POST['type'];
                    $name = $_POST['name'];
                    $link_to = $_POST['link_to'];
                    $ordering = $_POST['ordering'];
                    $created_date = date("F j, Y, g:i a");
                    $last_edit = date("F j, Y, g:i a");
                    if(isset($_POST['published'])){
                        $status = 1;
                    }
                    else{
                        $status = 0;
                    }
                    if($name == ""){
                        header("location: alert_box.php?opt=empty");
                    }
                    else{
                        
                        $table = "menu";
                        $cols = "menu_id,type,name,link_to,ordering,
                                 status,created_date,last_edit
                                 ";
                        $values = "'','$type','$name','$link_to','$ordering',
                                  '$status','$created_date','$last_edit'
                                  ";
                        $query = "INSERT INTO menu ($cols) 
                                  VALUES ($values)
                                 ";
                        $result = mysql_query($query);
                        if($result){
                            header("location: index.php?content=menus");
                        }
                        else{
                            header("location: alert_box.php?opt=not_insert");
                        }
                    }
                break;
                case "more":
                    if(isset($_GET['id'])){
                        $menu_id = $_GET['id'];
                        $query = "SELECT * FROM menu 
                                  WHERE menu_id = '$menu_id'
                                  ";
                        $result = mysql_query($query);
                        $cnt_records = mysql_num_rows($result);
                        if($cnt_records > 0){
                            require("menu_editing_form.php");
                        }
                    }
                break;
                case "edit":
                    $menu_id = $_POST['menu_id'];
                    $type = $_POST['type'];
                    $name = $_POST['name'];
                    $link_to = $_POST['link_to'];
                    $ordering = $_POST['ordering'];
                    $last_edit = date("F j, Y, g:i a");
                    if(isset($_POST['published'])){
                        $status = 1;
                    }
                    else{
                        $status = 0;
                    }
                    if($name == ""){
                        header("location: alert_box.php?opt=empty");
                    }
                    else{
                        $set = "type = '$type', 
                                name = '$name',
                                link_to = '$link_to',
                                ordering = '$ordering', 
                                status = '$status', 
                                last_edit = '$last_edit' ";
                        $query = "
                                 UPDATE menu
                                 SET $set 
                                 WHERE menu_id = '$menu_id'
                                 ";
                        $result = mysql_query($query);
                        if($result){
                            header("location: index.php?content=menus");
                        }
                        else{
                            header("location: alert_box.php?opt=not_updated");
                        }
                    }
                break;

Thanks a lot
Quyen,

Re: Problem with page redirecting: header("Location: $url");

ok, thefirst correction l will do in your code is to change the position of the require.

        case 'formAdd':
                    require_once("menu_adding_form.php");
                break;


should be:
<?php
     require_once("menu_adding_form.php");
     
    then  switch something  eg. switch($v){
       
       case 'formAdd':
                 


                break;


}
?>


If u need more assist let me know..

Last edited by christalix (2009-11-12 14:17:32)

Re: Problem with page redirecting: header("Location: $url");

christalix wrote:

ok, thefirst correction l will do in your code is to change the position of the require.

That would change the functionality -- there is nothing wrong with that particular line of code. The issue is about the header, not the include.

Re: Problem with page redirecting: header("Location: $url");

What is on line 15?

Or better yet, post the full page code, please.
There must be nothing (even a blank space) sent to the Browser before the header(), or that error results. Check in your included/required files as well.

*edit*

Wrap the entire page in an ob_start() function to avoid a leak to the browser.

http://php.net/manual/en/function.ob-start.php

Last edited by jlhaslip (2009-11-12 21:02:19)

Re: Problem with page redirecting: header("Location: $url");

Hello everyone,

Thanks a lot for your all replies, I do want to post all the coding which are require or include for you, but I'm wondering that my php pages are quite long, I hope you guys can understand all.
Please let me know if there is anything wrong. Sorry  I didn't comment much in my php code, I should do that but sorry i am too busy. If you need any futher information, let me know pls.
Thanks a lot again

"The main problem occurs in menu_manager.php file, I think"
Quyen,

file content.php:

<div class="page-wrapper">
<?php 
if(!isset($_SESSION['user_id'])){
    header("location: alert_box.php?opt=no_permission");
}
else{
    if(isset($_GET["content"])){
        $content = $_GET["content"];
        switch($content){
            case "home":
            break;
            case "menus":
                require_once("menu_manager.php");
            break;
            case "users":
                require_once("user_manager.php");
            break;
            case "portfolio":
            break;
            case "cart":
            break;
        }
    }
}
?>
</div>

file menu_manager.php:

<?php                
    $query = "SELECT * FROM menu 
              ORDER BY last_edit DESC";
    $result = mysql_query($query);
    $cnt_records = mysql_num_rows($result);
    if($cnt_records){
    $per_page = 10;
    $start = 0;
    $num_of_page = ceil($cnt_records/$per_page);
    if(isset($_GET['page'])){
        $get_request = $_GET['page'];
        if($get_request!="")
        {
            $start = ($get_request-1) * $per_page;
        }
        else
        {
            $start = 0;
        }
    }
    else{
    }
    ?>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    
        <div class="sub-menuitems">
            <form name="formPaging" id="formPaging" action="index.php?content=menus" method="post"> 
            <?php 
            if($num_of_page >=2){
            ?>
            <div class="items">
                Page:
                <select name="page" id="page" onchange="document.formPaging.submit()">
                    <option selected="selected">Select one</option>
                    <?php 
                    for($index=1;$index <= $num_of_page;$index++)
                    {
                        if($get_request == $index)
                        {
                            
                            echo "<option value=$index>$index </font>";
                        }
                        else
                        {
                            echo "<option value=$index>$index </font>";
                        }    
                    }
                    ?>
                </select>
                <?php 
                if(isset($_POST['page'])){
                    $selected = $_POST['page'];
                    for($index=1;$index <= $num_of_page;$index++)
                    {
                        if($get_request == $selected)
                        {
                            header("location: index.php?content=menus&page=$selected");
                        }
                        else
                        {
                            header("location: index.php?content=menus&page=$selected");
                        }    
                    }
                }
                ?>
            </div>
            <?php 
            }
            ?>
            </form>
            <form name="formMenuitemQuickLaunch" id="formMenuitemQuickLaunch" action="index.php?content=menus&act=item" method="post">
            <div class="items">   
                Item: 
                <select name="menu_id" id="menu_id" onchange="document.formMenuitemQuickLaunch.submit();">
                    <option>Select one</option>
                <?php 
                if($cnt_records){
                    while($row = mysql_fetch_array($result)){
                        ?>
                        <option value="<?php print $row['menu_id'];?>">
                            <?php 
                            print $row['name']."--"; 
                            if($row['type']==0){print "B";}else{print "F";}
                            ?>
                        </option>
                        <?php
                    }
                }
                ?>
                </select>
            </div>
            </form>
            <form name="formMenuGroup" id="formMenuGroup" action="index.php?content=menus&page=1" method="post"> 
            <div class="items">
                Quick launch: 
                <select name="menuType" id="menuType" onchange="document.formMenuGroup.submit();">
                    <option value="none">Select one</option>
                    <option value="all">All</option>
                    <option value="backend">Back-End</option>
                    <option value="frontend">Front-End</option>
                    <option value="published">Published</option>
                    <option value="unpublished">Un-Published</option>
                </select>
            </div>   
            </form> 
        </div>
        <div class="sub-menuitems">
            <div class="items">
                <a href="#">Delete</a>
            </div>
            <div class="items">
                <a href="#">Published</a>
            </div>
            <div class="items">
                <a href="#">None</a>
            </div>
            <div class="items">
                <a href="#" onclick="">Select All</a>
            </div>
            
            <div class="items">
                <a href="index.php?content=menus&act=formAdd">Add</a>
            </div>
        </div>
        <?php 
        if(!isset($_GET['act'])){
            require_once("menu_content.php");
        }
        else{
            $action = $_GET['act'];
            switch($action){
                case"item":
                    if(isset($_POST['menu_id'])){
                        $menu_id = $_POST['menu_id'];
                        $query = "SELECT * FROM menu
                                  WHERE menu_id = '$menu_id'
                                  ";
                        $result_items = mysql_query($query);
                        $cnt_records = mysql_num_rows($result_items);
                        if($cnt_records){
                        ?>
                        <div class="sub-content">
                        <table>
                            <tr class="col-title">
                                <td>ID</td>
                                <td>Group</td>
                                <td>Name</td>
                                <td>Link name </td>
                                <td>Ordering</td>
                                <td>Published</td>
                                <td>Details</td>
                                <td>Edit</td>
                                <td>Delete</td>
                                <td>#</td>
                            </tr>
                        <?php
                            while($row = mysql_fetch_array($result_items)){
                                require("menu_list.php");
                            }
                        ?>
                        </table>
                        </div>
                        <?php    
                        }
                    }
                break;
                
                case "pos":
                    if(isset($_POST['pos'])){
                        $ordering= $_POST['pos'];
                        $menu_id = $_POST['menu_id'];
                        $last_edit = date("F j, Y, g:i a");
                        $query = "UPDATE menu
                                SET ordering = '$ordering',last_edit = '$last_edit'
                                WHERE menu_id = '$menu_id' 
                                ";
                        $result = mysql_query($query);
                        $cnt_records = mysql_num_rows($result);
                        if($result){
                            header("location: index.php?content=menus");
                        }
                    }
                break;
                case 'formAdd':
                    require_once("menu_adding_form.php");
                break;
                case 'add':
                    $type = $_POST['type'];
                    $name = $_POST['name'];
                    $link_to = $_POST['link_to'];
                    $ordering = $_POST['ordering'];
                    $created_date = date("F j, Y, g:i a");
                    $last_edit = date("F j, Y, g:i a");
                    if(isset($_POST['published'])){
                        $status = 1;
                    }
                    else{
                        $status = 0;
                    }
                    if($name == ""){
                        header("location: alert_box.php?opt=empty");
                    }
                    else{
                        
                        $table = "menu";
                        $cols = "menu_id,type,name,link_to,ordering,
                                 status,created_date,last_edit
                                 ";
                        $values = "'','$type','$name','$link_to','$ordering',
                                  '$status','$created_date','$last_edit'
                                  ";
                        $query = "INSERT INTO menu ($cols) 
                                  VALUES ($values)
                                 ";
                        $result = mysql_query($query);
                        if($result){
                            header("location: index.php?content=menus");
                        }
                        else{
                            header("location: alert_box.php?opt=not_insert");
                        }
                    }
                break;
                case "more":
                    if(isset($_GET['id'])){
                        $menu_id = $_GET['id'];
                        $query = "SELECT * FROM menu 
                                  WHERE menu_id = '$menu_id'
                                  ";
                        $result = mysql_query($query);
                        $cnt_records = mysql_num_rows($result);
                        if($cnt_records > 0){
                            require("menu_editing_form.php");
                        }
                    }
                break;
                case "edit":
                    $menu_id = $_POST['menu_id'];
                    $type = $_POST['type'];
                    $name = $_POST['name'];
                    $link_to = $_POST['link_to'];
                    $ordering = $_POST['ordering'];
                    $last_edit = date("F j, Y, g:i a");
                    if(isset($_POST['published'])){
                        $status = 1;
                    }
                    else{
                        $status = 0;
                    }
                    if($name == ""){
                        header("location: alert_box.php?opt=empty");
                    }
                    else{
                        $set = "type = '$type', 
                                name = '$name',
                                link_to = '$link_to',
                                ordering = '$ordering', 
                                status = '$status', 
                                last_edit = '$last_edit' ";
                        $query = "
                                 UPDATE menu
                                 SET $set 
                                 WHERE menu_id = '$menu_id'
                                 ";
                        $result = mysql_query($query);
                        if($result){
                            header("location: index.php?content=menus");
                        }
                        else{
                            header("location: alert_box.php?opt=not_updated");
                        }
                    }
                break;
                case "delete":
                    if(!isset($_GET['id'])){}
                    else{
                        $menu_id = $_GET['id'];
                        $query = "DELETE FROM menu
                                  WHERE menu_id = '$menu_id';
                                 ";
                        $result = mysql_query($query);
                        if($result){
                            header("index.php?content=menus");
                        }
                        else{
                            print mysql_error();
                            
                            header("alert_box.php?opt=delete_error");
                        }
                    }
                break;
                
                case "status":
                    if(isset($_GET['id']) && isset($_GET['cur'])){
                        $menu_id = $_GET['id'];
                        $last_edit = date("F j, Y, g:i a");
                        $current_status = $_GET['cur'];
                        if($current_status == 0){
                            $status = 1;
                        }
                        elseif($current_status == 1){
                            $status = 0;
                        }
                        else{
                            header("location: alert_box.php?opt=no_permission");
                        }
                        $query = "UPDATE menu
                                  SET status = '$status', last_edit = '$last_edit' 
                                  WHERE menu_id = $menu_id
                                 ";
                        $result = mysql_query($query);
                        if($result){
                            header("location: index.php?content=menus&page=1");
                        }
                        else{
                            header("location: alert_box.php?opt=not_updated");
                        }
                    }
                break;
            }
        }
    } 
?>

Required files:
menu_list.php

<tr>
    <td>
        <?php print $row['menu_id']?>
    </td>
    <td>
        <?php 
        if($row['type'] == 1){
            print "Front-end";
        }
        else{
            print "Back-end";
        }
        ?>
    </td>
    <td>
        <?php print $row['name'];?>
    </td>
    <td>
        <?php print $row['link_to'];?>
    </td>
    <form name="orderingForm" id="orderingForm" action="index.php?content=menus&act=pos&page=1" method="post">
    <td>
        <?php 
            print $row['ordering'];
            $current_id = $row['menu_id'];
        ?>
        <input type="hidden" name="menu_id" id="menu_id" value="<?php print $current_id;?>" />
        <?php 
        if(!isset($_GET['act'])){
        }
        else{
            ?>
            <select name="pos" id="pos" onchange="submitFormOrdering()">
                <option selected="selected">Select</option>
                <?php 
                $query = "SELECT * FROM menu";
                $result = mysql_query($query);
                $cnt_records = mysql_num_rows($result);
                for($i= 1; $i<= $cnt_records; $i++){
                    ?>
                    <option><?php print $i;?></option>
                    <?php
                }
                ?>
            </select>
         <?php 
             }
         ?>
    </td>
    </form>
    <td>
        <?php 
        if($row['status'] == 1){
            print "<a href='index.php?content=menus&act=status&id="; print $row['menu_id']."&cur="; print $row['status']."'><font color='#FF3300'>Yes</font> </a>";
        }
        else{
            print "<a href='index.php?content=menus&act=status&id="; print $row['menu_id']."&cur="; print $row['status']."'><font color='#006600'> No </font> </a>";

        }
        ?>
    </td>
        <td>
            <a href="index.php?content=menus&act=more&id=<?php print $row['menu_id'];?>">Detail</a>
        </td>
    <td>
        <a href="index.php?content=menus&act=more&id=<?php print $row['menu_id'];?>">Edit</a>
    </td>
    <td>
        <a href="index.php?content=menus&act=delete&id=<?php print $row['menu_id'];?>">Delete</a>
    </td>
    <td>
    <form name="multiSelectedForm" id="multiSelectedForm">
        <input type="checkbox" name="selectedItems" id="selectedItems" />
    </form>
    </td>
</tr>

menu_adding_form.php

<link href="css/style.css" rel="stylesheet" type="text/css" />
<div class="sub-content">
    <table>
        <tr class="form-title">
            <td colspan="2">Add a new menuitem</td>
        </tr>
        <form name="menuAddingForm" id="menuAddingForm" method="post" action="index.php?content=menus&act=add">
        <tr>
            <td class="comp-title">Group of menu </td>
            <td>
                <select name="type" id="type">
                    <option value="1">Front-End</option>
                    <option value="0">Back-End</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="comp-title">Menuitem name</td>
            <td><input type="text" name="name" id="name" /></td>
        </tr>
        <tr>
            <td class="comp-title">Link to</td>
            <td>
                <select name="link_to" id="link_to">
                    <option value="home">Home page</option>
                    <option value="aboutus">About Us</option>
                    <option value="webdesigns">Web Designs</option>
                    <option value="webtemplates">Web Templates</option>
                    <option value="contact">Contact Us</option>
                    <option value="cart">Shopping Cart</option>
                    
                    <option value="menus">Menus</option>
                    <option value="users">Users</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="comp-title">Ordering</td>
            <td>
                <select name="ordering" id="ordering">
                    <?php 
                    $query = "SELECT * FROM menu";
                    $result = mysql_query($query);
                    $cnt_records = mysql_num_rows($result);
                    for($i= 1; $i<= $cnt_records; $i++){
                        print '<option>'.$i.'</option>';
                    }
                    ?>
                    <option><?php print $cnt_records + 1?></option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="comp-title">Published</td>
            <td>
                <input type="checkbox" name="published" id="published"/>
            </td>
        </tr>
        <tr>
            <td class="comp-title"> Enter or click
            </td>
            <td>
                <input type="submit" value="Save this record"/>
                <input type="reset"  name="reset" value="Reset"/>
                <input type="reset"  name="cancel" value="Cancel" onClick="javascript: history.go(-1);"/>
            </td>
        </tr>
        </form>
    </table>
</div>

menu_editing_form.php

<div class="sub-content">
    <table>
        <tr class="form-title">
            <td colspan="2">Detail of menuitems <font color="#CC3300"> " <?php print $menu_id; ?> "</font></td>
        </tr>
        <form name="menuEditingForm" id="menuEditingForm" method="post" action="index.php?content=menus&act=edit">
        <tr>
            <td class="comp-title">Group of menu </td>
            <td>
                <select name="type" id="type">
                    <?php 
                    while($row = mysql_fetch_array($result)){
                    ?>
                    <option value="<?php  print $row['type'];?>" selected>
                        <?php 
                        $menu_id = $row['menu_id'];
                        $type = $row['type'];
                        $name = $row['name'];
                        $link_to = $row['link_to'];
                        $status = $row['status'];
                        $ordering = $row['ordering'];
                        $created_date = $row['created_date'];
                        $last_edit = $row['last_edit'];
                        if($type ==  0){
                            print "Back-End";
                        }
                        else{
                            print "Front-End";
                        }
                        ?>
                    </option>
                    <?php 
                    }
                    if($type == 0){
                        ?>
                        <option value="1" >Front-End</option>
                        <?php
                    }
                    else{
                        ?>
                        <option value="0" >Back-End</option>
                        <?php
                    }
                    ?>
                </select>
                <input type="hidden" name="menu_id" id="menu_id" value="<?php print $menu_id; ?>">
            </td>
        </tr>
        <tr>
            <td class="comp-title">Menuitem name</td>
            <td><input type="text" name="name" id="name"  value="<?php print  $name; ?>"/></td>
        </tr>
        <tr>
            <td class="comp-title">Link to</td>
            <td>
                
                <select name="link_to" id="link_to">
                    <option value="<?php print $link_to;?>" selected><?php print $link_to;?></option>
                    <?php 
                    $query = "SELECT * FROM menu
                              WHERE link_to <> '$link_to'
                              ORDER BY ordering ASC
                             ";
                    $result = mysql_query($query);
                    $cnt_records = mysql_num_rows($result);
                    if($cnt_records){
                        while($row = mysql_fetch_array($result)){
                            $type = $row['type'];
                        ?>
                        <option value="<?php print $row['link_to'];?>">
                            <?php 
                            print $row['link_to']."--";
                            if($type == 0){
                                print "Back";
                            }
                            else{
                                print "Front";
                            }
                            ?>
                        </option>
                        <?php
                        }
                    }
                    ?>
                </select>
            </td>
           
        </tr>
        <tr>
            <td class="comp-title">Ordering</td>
            <td>
                <select name="ordering" id="ordering">
                    <?php 
                    $query = "SELECT * FROM menu";
                    $result = mysql_query($query);
                    $cnt_records = mysql_num_rows($result);
                    for($i= 1; $i<= $cnt_records; $i++){
                    $start = $i + 1;
                    ?>
                    <option <?php if($ordering == $i){?>selected="selected" <?php }?>>
                        <?php  print $i;?>
                    </option>
                    <?php
                    }
                    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="comp-title">Published</td>
            <td>
                <input type="checkbox" name="published" id="published" <?php if ($status == true){ ?>checked<?php } ?> />
            </td>
        </tr>
        <tr>
            <td class="comp-title">Created on </td>
            <td>
                <label><?php print $created_date; ?></label>
            </td>
        </tr>
        <tr>
            <td class="comp-title">Last edited</td>
            <td>
                <label><?php print $last_edit ; ?></label>
            </td>
        </tr>
        <tr>
            <td class="comp-title"> Enter or click
            </td>
            <td>
                <input type="submit" value="Save this record"/>
                <input type="reset"  name="reset" value="Reset"/>
                <input type="reset"  name="cancel" value="Cancel" onClick="javascript: history.go(-1);"/>
            </td>
        </tr>
        </form>
    </table>
</div>

Last edited by quyen (2009-11-13 00:36:27)