Проблем с header

Knoppix_

Registered
Здравейте, имам следният проблем като си преглеждам кода всичко ми е наред но когато потвърдя формата не ми се изпълнявам функцията header

Това е кода

Код:
 // check to make sure both fields are entered
 if ($omsan_kamion == '' || $omsan_vlekach == '' || $omsan_data == '' || $omsan_firma == '' || $omsan_destination == '')
 {
 // generate error message
 $error = 'Грешка: Моля попълнете задължителните полета!';
 
 // if either field is blank, display the form again
 renderForm($omsan_kamion, $omsan_vlekach, $omsan_evropa, $omsan_evropa2, $omsan_turcia, $omsan_turcia2, $omsan_data, $omsan_data2, $omsan_destination, $omsan_firma, $omsan_cemt, $omsan_zabelejka, $error);
 }
 else
 {
 // save the data to the database
 mysql_query("SET CHARACTER SET utf8");
 mysql_query("INSERT spisak_omsan SET kamion='$omsan_kamion', vlekach='$omsan_vlekach', shofior_evropa='$omsan_evropa', shofior_evropa2='$omsan_evropa2', shofior_turcia='$omsan_turcia', shofior_turcia2='$omsan_turcia2', data_trugvane='$omsan_data', data_pribirane='$omsan_data2', destination='$omsan_destination', firma='$omsan_firma', cemt='$omsan_cemt', zabelejka='$omsan_zabelejka' ")
 or die(mysql_error()); 
 
 // once saved, redirect back to the view page
 header("Location: ?page=success"); 
 }
 }
 else
 // if the form hasn't been submitted, display the form
 {
 renderForm('','','','','','','','','','','','','');
 }
?>

Някой да има някакви предположения
 
Дава ли някаква грешка. Дай малко по-нагоре кода, защото си мисля, че може би от там идва грешката.
 
Грешка не давапросто остава в същата страница като даже и не визуализира формата наново ето го целият код

Код:
<link rel="stylesheet" type="text/css" href="scripts/demos.css">
<?php
/* 
 NEW.PHP
 Allows user to create a new entry in the database
*/
 
 // creates the new record form
 // since this form is used multiple times in this file, I have made it a function that is easily reusable
 function renderForm($omsan_kamion, $omsan_vlekach, $omsan_evropa, $omsan_evropa2, $omsan_turcia, $omsan_turcia2, $omsan_data, $omsan_data2, $omsan_destination, $omsan_firma, $omsan_cemt, $omsan_zabelejka, $error)
 {
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
 <title>New Record</title>
 </head>
 <body>
 <?php 
 // if there are any errors, display them
 if ($error != '')
 {
 echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?> 
 
 <form action="" method="post">
 <div>
 <table>
 <tr>
 <td><strong>Влекач: *</strong></td><td><input type="text" name="omsan_kamion" id="omsan_kamion" value="<?php echo $omsan_kamion; ?>" /></td>
 <tr>
 <tr>
 <td><strong>Ремарке: *</strong></td><td><input type="text" name="omsan_vlekach" id="omsan_vlekach" value="<?php echo $omsan_vlekach; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Шофьор в Европа: *</strong></td><td><input type="text" name="omsan_evropa" id="omsan_evropa"  value="<?php echo $omsan_evropa; ?>" /></td>
 </tr>
 <tr>
 <td><strong>II-ри Шофьор в Европа: </strong></td><td><input type="text" name="omsan_evropa2" id="omsan_evropa2" value="<?php echo $omsan_evropa2; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Шофьор в Турция: *</strong></td><td><input type="text" name="omsan_turcia" id="omsan_turcia" value="<?php echo $omsan_turcia; ?>" /></td>
 </tr>
 <tr>
 <td><strong>II-ри Шофьор в Турция: </strong></td><td><input type="text" name="omsan_turcia2" id="omsan_turcia2" value="<?php echo $omsan_turcia2; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Дата на тръгване: *</strong></td><td><input type="text" name="omsan_data" id="omsan_data" value="<?php echo $omsan_data; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Дата на прибиране: </strong></td><td><input type="text" name="omsan_data2" id="omsan_data2" value="<?php echo $omsan_data2; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Дестинация: *</strong></td><td><input type="text" name="omsan_destination" id="omsan_destination" value="<?php echo $omsan_destination; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Фирма: *</strong></td><td><input type="text" name="omsan_firma" id="omsan_firma" value="<?php echo $omsan_firma; ?>" /></td>
 </tr>
 <tr>
 <td><strong>СЕМТ: *</strong></td><td><input type="text" name="omsan_cemt" id="omsan_cemt" value="<?php echo $omsan_cemt; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Забележка: </strong></td><td><input type="text" name="omsan_zabelejka" id="omsan_zabelejka" value="<?php echo $omsan_zabelejka; ?>" /></td>
 </tr>
 <tr>
 <td colspan="2" align="center"><p>* Задължителни полета</p></td>
 </tr>
 <tr>
 <td></td><td><input type="submit" name="submit" value="Добави"></td>
 </tr>
 </table>
 
 </div>
 </form> 
 </body>
 </html>
 <?php 
 }
 
 
 

 // connect to the database
 include('connect-db.php');
 
 // check if the form has been submitted. If it has, start to process the form and save it to the database
 if (isset($_POST['submit']))
 { 
 // get form data, making sure it is valid
 $omsan_kamion = mysql_real_escape_string(htmlspecialchars($_POST['omsan_kamion']));
 $omsan_vlekach = mysql_real_escape_string(htmlspecialchars($_POST['omsan_vlekach']));
 $omsan_evropa = mysql_real_escape_string(htmlspecialchars($_POST['omsan_evropa']));
 $omsan_evropa2 = mysql_real_escape_string(htmlspecialchars($_POST['omsan_evropa2']));
 $omsan_turcia = mysql_real_escape_string(htmlspecialchars($_POST['omsan_turcia']));
 $omsan_turcia2 = mysql_real_escape_string(htmlspecialchars($_POST['omsan_turcia2']));
 $omsan_data = mysql_real_escape_string(htmlspecialchars($_POST['omsan_data']));
 $omsan_data2 = mysql_real_escape_string(htmlspecialchars($_POST['omsan_data2']));
 $omsan_destination = mysql_real_escape_string(htmlspecialchars($_POST['omsan_destination']));
 $omsan_firma = mysql_real_escape_string(htmlspecialchars($_POST['omsan_firma']));
 $omsan_cemt = mysql_real_escape_string(htmlspecialchars($_POST['omsan_cemt']));
 $omsan_zabelejka = mysql_real_escape_string(htmlspecialchars($_POST['omsan_zabelejka']));
 
 // check to make sure both fields are entered
 if ($omsan_kamion == '' || $omsan_vlekach == '' || $omsan_data == '' || $omsan_firma == '' || $omsan_destination == '')
 {
 // generate error message
 $error = 'Грешка: Моля попълнете задължителните полета!';
 
 // if either field is blank, display the form again
 renderForm($omsan_kamion, $omsan_vlekach, $omsan_evropa, $omsan_evropa2, $omsan_turcia, $omsan_turcia2, $omsan_data, $omsan_data2, $omsan_destination, $omsan_firma, $omsan_cemt, $omsan_zabelejka, $error);
 }
 else
 {
 // save the data to the database
 mysql_query("SET CHARACTER SET utf8");
 mysql_query("INSERT spisak_omsan SET kamion='$omsan_kamion', vlekach='$omsan_vlekach', shofior_evropa='$omsan_evropa', shofior_evropa2='$omsan_evropa2', shofior_turcia='$omsan_turcia', shofior_turcia2='$omsan_turcia2', data_trugvane='$omsan_data', data_pribirane='$omsan_data2', destination='$omsan_destination', firma='$omsan_firma', cemt='$omsan_cemt', zabelejka='$omsan_zabelejka' ")
 or die(mysql_error()); 
 
 // once saved, redirect back to the view page
 header("Location: http://localhost/spisaci/index.php?page=success"); 
 }
 }
 else
 // if the form hasn't been submitted, display the form
 {
 renderForm('','','','','','','','','','','','','');
 }
?>
 
Грешката най-вероятно идва от <link rel="stylesheet" type="text/css" href="scripts/demos.css"> в началото на файла ти.

От php.net/header се разбира:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
 
ММне ... отгоре в браузъра връща това

http://localhost/spisaci/index.php?page=new

а би трябвало да е http://localhost/spisaci/index.php?page=success
 
Knoppix_ каза:
ММне ... отгоре в браузъра връща това

http://localhost/spisaci/index.php?page=new

а би трябвало да е http://localhost/spisaci/index.php?page=success

Нали страницата с формата е page=new..? Следователно не е пренасочена страницата, а само е събмитната формата. Преди header не трябва да има някакъв html, празни редове и т.н. Сложи все пак едно error_reporting(E_ALL); след първото <?php
 
Ето го

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\spisaci\index.php:140) in C:\xampp\htdocs\spisaci\pages\new.php on line 122


Те това е в индекса на 140 линия

<?php
$p = $_GET['page'];

$page = "pages/".$p.".php";

if(file_exists($page))
include($page);
elseif($p=="")
include('pages/start.php');
else
echo "what are you looking for! ?";

?>
 
Така? Като гледай да го копираш без празни редове или символи преди първото <?php

Код:
<?php 
ob_start();
?>
<link rel="stylesheet" type="text/css" href="scripts/demos.css">
<?php
/* 
 NEW.PHP
 Allows user to create a new entry in the database
*/
 
 // creates the new record form
 // since this form is used multiple times in this file, I have made it a function that is easily reusable
 function renderForm($omsan_kamion, $omsan_vlekach, $omsan_evropa, $omsan_evropa2, $omsan_turcia, $omsan_turcia2, $omsan_data, $omsan_data2, $omsan_destination, $omsan_firma, $omsan_cemt, $omsan_zabelejka, $error)
 {
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
 <title>New Record</title>
 </head>
 <body>
 <?php 
 // if there are any errors, display them
 if ($error != '')
 {
 echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?> 
 
 <form action="" method="post">
 <div>
 <table>
 <tr>
 <td><strong>Влекач: *</strong></td><td><input type="text" name="omsan_kamion" id="omsan_kamion" value="<?php echo $omsan_kamion; ?>" /></td>
 <tr>
 <tr>
 <td><strong>Ремарке: *</strong></td><td><input type="text" name="omsan_vlekach" id="omsan_vlekach" value="<?php echo $omsan_vlekach; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Шофьор в Европа: *</strong></td><td><input type="text" name="omsan_evropa" id="omsan_evropa"  value="<?php echo $omsan_evropa; ?>" /></td>
 </tr>
 <tr>
 <td><strong>II-ри Шофьор в Европа: </strong></td><td><input type="text" name="omsan_evropa2" id="omsan_evropa2" value="<?php echo $omsan_evropa2; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Шофьор в Турция: *</strong></td><td><input type="text" name="omsan_turcia" id="omsan_turcia" value="<?php echo $omsan_turcia; ?>" /></td>
 </tr>
 <tr>
 <td><strong>II-ри Шофьор в Турция: </strong></td><td><input type="text" name="omsan_turcia2" id="omsan_turcia2" value="<?php echo $omsan_turcia2; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Дата на тръгване: *</strong></td><td><input type="text" name="omsan_data" id="omsan_data" value="<?php echo $omsan_data; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Дата на прибиране: </strong></td><td><input type="text" name="omsan_data2" id="omsan_data2" value="<?php echo $omsan_data2; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Дестинация: *</strong></td><td><input type="text" name="omsan_destination" id="omsan_destination" value="<?php echo $omsan_destination; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Фирма: *</strong></td><td><input type="text" name="omsan_firma" id="omsan_firma" value="<?php echo $omsan_firma; ?>" /></td>
 </tr>
 <tr>
 <td><strong>СЕМТ: *</strong></td><td><input type="text" name="omsan_cemt" id="omsan_cemt" value="<?php echo $omsan_cemt; ?>" /></td>
 </tr>
 <tr>
 <td><strong>Забележка: </strong></td><td><input type="text" name="omsan_zabelejka" id="omsan_zabelejka" value="<?php echo $omsan_zabelejka; ?>" /></td>
 </tr>
 <tr>
 <td colspan="2" align="center"><p>* Задължителни полета</p></td>
 </tr>
 <tr>
 <td></td><td><input type="submit" name="submit" value="Добави"></td>
 </tr>
 </table>
 
 </div>
 </form> 
 </body>
 </html>
 <?php 
 }
 
 
 

 // connect to the database
 include('connect-db.php');
 
 // check if the form has been submitted. If it has, start to process the form and save it to the database
 if (isset($_POST['submit']))
 { 
 // get form data, making sure it is valid
 $omsan_kamion = mysql_real_escape_string(htmlspecialchars($_POST['omsan_kamion']));
 $omsan_vlekach = mysql_real_escape_string(htmlspecialchars($_POST['omsan_vlekach']));
 $omsan_evropa = mysql_real_escape_string(htmlspecialchars($_POST['omsan_evropa']));
 $omsan_evropa2 = mysql_real_escape_string(htmlspecialchars($_POST['omsan_evropa2']));
 $omsan_turcia = mysql_real_escape_string(htmlspecialchars($_POST['omsan_turcia']));
 $omsan_turcia2 = mysql_real_escape_string(htmlspecialchars($_POST['omsan_turcia2']));
 $omsan_data = mysql_real_escape_string(htmlspecialchars($_POST['omsan_data']));
 $omsan_data2 = mysql_real_escape_string(htmlspecialchars($_POST['omsan_data2']));
 $omsan_destination = mysql_real_escape_string(htmlspecialchars($_POST['omsan_destination']));
 $omsan_firma = mysql_real_escape_string(htmlspecialchars($_POST['omsan_firma']));
 $omsan_cemt = mysql_real_escape_string(htmlspecialchars($_POST['omsan_cemt']));
 $omsan_zabelejka = mysql_real_escape_string(htmlspecialchars($_POST['omsan_zabelejka']));
 
 // check to make sure both fields are entered
 if ($omsan_kamion == '' || $omsan_vlekach == '' || $omsan_data == '' || $omsan_firma == '' || $omsan_destination == '')
 {
 // generate error message
 $error = 'Грешка: Моля попълнете задължителните полета!';
 
 // if either field is blank, display the form again
 renderForm($omsan_kamion, $omsan_vlekach, $omsan_evropa, $omsan_evropa2, $omsan_turcia, $omsan_turcia2, $omsan_data, $omsan_data2, $omsan_destination, $omsan_firma, $omsan_cemt, $omsan_zabelejka, $error);
 }
 else
 {
 // save the data to the database
 mysql_query("SET CHARACTER SET utf8");
 mysql_query("INSERT spisak_omsan SET kamion='$omsan_kamion', vlekach='$omsan_vlekach', shofior_evropa='$omsan_evropa', shofior_evropa2='$omsan_evropa2', shofior_turcia='$omsan_turcia', shofior_turcia2='$omsan_turcia2', data_trugvane='$omsan_data', data_pribirane='$omsan_data2', destination='$omsan_destination', firma='$omsan_firma', cemt='$omsan_cemt', zabelejka='$omsan_zabelejka' ")
 or die(mysql_error()); 
 
 // once saved, redirect back to the view page
 header("Location: http://localhost/spisaci/index.php?page=success"); 
die;
 }
 }
 else
 // if the form hasn't been submitted, display the form
 {
 renderForm('','','','','','','','','','','','','');
 }
?>
 
Мне това кеото ми го даде ефекта е същият ;(

А между другото до онзи ден работеше
 
Knoppix_ каза:
Мне това кеото ми го даде ефекта е същият ;(

А между другото до онзи ден работеше

Дай му файлва Save as и го запиши като UTF-8 without BOM. Ако и това не става използвай <meta http-equiv="refresh"..... за редиректа.
 
Използвам хедър в още един файл това е причината да не стане, между другото за да не отварям нова тема, някой може ли дам и даде добра юзър система която да пази историята, т.е да мога да виждам какво прави определен потребител
 

Back
Горе