Jump to content

i need help


azeem123456

Recommended Posts

 

i m having problem in redirecting  im making content management system

i get a values from posted form and then insert as an new row value is  inserted correctly but i want to redirect it back to my content.php when i use header("Location: content.php");

it gives me this error when i fill form and hit submit error is "Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\widget_corp\includes\connection.php:1) in C:\xampp\htdocs\widget_corp\create_subject.php on line 14"

and my code is <?php

$menu_name= $_POST['menu_name'];

$position = $_POST['position'];

$visible = $_POST['visible'];

 

$query = "INSERT INTO subjects (

      menu_name, position, visible)

      Values ( '{$menu_name}',{$position},{$visible})";

if(mysql_query($query,$connection)){

  header("Location: content.php");

  exit;

}else {

  echo "<p> Subject creation is failed .</p>";

  echo "<p>".mysql_error()."</p>";

}

please please help me out

 

Link to comment
Share on other sites

this is my content.php file i have made nevigation fucntion seperatly and to snow u my content.php i j ust copy paste  my function here there might be sysntax errors but i m sure u will get idea 

 

?php require_once("includes/connection.php");?>

<?php require_once("includes/functions.php");?>

<?php find_selected_page();?>

<?php

include("includes/header.php");

      ?>     

<table id="Structure">

            <tr>               

                  <td id="nevigation">

///////////////////////////////////////////////////

echo"<ul class=\"subjects\">";

$subject_set=get_all_subjects();

while ($subject=mysql_fetch_array($subject_set)){

echo "<li<a href=\"content.php?subj=".urlencode($subject["id"])."\">{$subject["menu_name"]}</a></li>";

 

$page_set = get_pages_for_subject($subject["id"]);

echo "<ul class=\"pages\">";

while ($page= mysql_fetch_array($page_set)){

echo "<li><a href=\"content.php?page=".urlencode($page["id"])."\">{$page["menu_name"]}</a></li>";

 

}

echo "</ul>";

}

 

 

                  echo" </ul>";

                    <br />

                        <a href="new_subject.php"> + ADD a new subject</a>

                    </td>

                    <td id="pages">

                    <?php if(!is_null($sel_subject)){?><h2><?php echo $sel_subject['menu_name'];?></h2><?php  }else if (!is_null($sel_page)){ ?>

                  <h2><?php echo $sel_page['menu_name'];?></h2>

<div class= "page_content">

                    <?php echo $sel_page['content'];?>

                    </div>

<?php }else { ?><h2> Select a subject or page to edit</h2>

                    <?php }?>

                                 

 

                      </td>

                    </tr>

                    </table>

                     

<?php require("includes/footer.php"); ?>

Link to comment
Share on other sites

this is my new_subject.php file  which has form in it to add new subject

?php require_once("includes/connection.php");?>

<?php require_once("includes/functions.php");?>

<?php

find_selected_page();

?>

<?php

include("includes/header.php");

?>     

<table id="Structure">

            <tr>

               

                  <td id="nevigation">

<?php navigation($sel_subject,$sel_page); ?>                   

                    </td>

                    <td id="pages">

                        <h2> Add Subject</h2>

                        <form action="create_subject.php" method="post">

                        <p> Subject name:<input type="text" name="menu_name" value="" id="menu_name" /></p>

                        <p> position: <select name="position">

                        <?php $subject_set= get_all_subjects();

$subject_count= mysql_num_rows($subject_set);

for ($count=1;$count<= $subject_count+1;$count++){

echo"<option value=\"{$count}\">{$count}</option>";

}

?>

                         

                        </select>

                        </p>

                        <p> visible : <input type="radio" name="visible" value="0" />No

                         

                        <input type="radio" name="visible" value="1" />YES

                        </p>

                        <input type="submit" value="Add Subject" />

                        </form>

                        <br/>

                        <a href="content.php">Cancel</a>

 

                      </td>

                    </tr>

                    </table>

                     

<?php require("includes/footer.php");?>

////////////////////////////////////////////////////////

when i run this file it works correctly and give me form

 

[attachment deleted by admin]

Link to comment
Share on other sites

after filling form my new file create_subject.php take all information this is code

 

<?php require_once("includes/connection.php");?>

<?php require_once("includes/functions.php");?>

<?php

$menu_name= $_POST['menu_name'];

$position = $_POST['position'];

$visible = $_POST['visible'];

$query = "INSERT INTO subjects (

menu_name, position, visible)

Values ( '{$menu_name}',{$position},{$visible})";

if(mysql_query($query,$connection)){

header("Location": "content.php");

exit;

}else {

echo "<p> Subject creation is failed .</p>";

echo "<p>".mysql_error()."</p>";

}

 

 

?>

<?php mysql_close($connection);?>

it add subject corrctly it add all subjects but it doesnt redirect me bak to my content.php page after adding information it gives error cannot modify header as i mention before

Link to comment
Share on other sites

if that connection.php is that secret, u dont want to show it

we cant help u,

cause that error message line (at your 1st post), the message stating the connection.php is having error.

if u dont show that, we cant help u

 

if you dont show the file, then we cant help even it is your final second

only god can help u

 

 

here is what i suggest you to do before showing that connection.php

use **** to replace the mysql address, username, password, db name

Link to comment
Share on other sites

as people here are trying to tell you, your error message clearly states:

 

output started at C:\xampp\htdocs\widget_corp\includes\connection.php:1)

 

That means that something on line 1 of that file, is producing output. It may be as simple as a space before the <?php or may be something else, but that is where your error is.

Link to comment
Share on other sites

oh i read it wrong sir i thought  u asking me content.php  sir i didnt make seperate db connection file

as i m new learner of php so i m not perfect in it there is nothing important for me sir.... all i want to learn and gain knowlegde sir could you tell me your email adress i send you my whole project and file to your email adress then u mite eaisly sort out my problem

ths is how i made my dataabase connection sir

<?php

$connection = mysql_connect("localhost","root","");

if (!$connection){

die ("Database connection failed".mysql_error());

}

$db_select= mysql_select_db("widget_corp",$connection);

 

if (!$db_select){

die ("Database selection failed".mysql_error());

}

?>

 

in html body 

there is my queries as u have seen above i provide you what you just asked me or give me email id  please

 

 

at the end i close my  conection ?php

mysql_close($connection);

?>

 

 

Link to comment
Share on other sites

his time same warning is appear but insteade of connection.php is saying create_subject.php

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\widget_corp\create_subject.php:1) in C:\xampp\htdocs\widget_corp\create_subject.php on line 11

 

check out it was C:\xampp\htdocs\widget_corp\connection.php:1) before

now this is in C:\xampp\htdocs\widget_corp\create_subject.php:1)

Link to comment
Share on other sites

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.