N
N
nehmet_b2019-02-18 10:36:44
PHP
nehmet_b, 2019-02-18 10:36:44

Can't send header?

I can't send the header, please help me, explain the width. How to get show_user.php ?
create_user.html

<form action="./scripts/create_user.php" method="POST" enctype="multipart/form-data">
        <fieldset>
            <label for="first_name">Имя:</label>
            <input type="text" name="first_name" size="20" /><br>
            <label for="last_name">Фамилия:</label>
            <input type="text" name="last_name" size="20"><br>
            <label for="email">Адрес электронной почты:</label>
            <input type="text" name="email" size="50">
            <label for="facebook_url">URL в Facebook:</label>
            <input type="text" name="facebook_url" size="50">
            <label for="twitter_handle">Идентификатор в Twitter:</label>
            <input type="text" name="twitter_handle" size="20"><br>
            <label for="bio">Биография:</label>
            <textarea name="bio" cols="40" rows="10"></textarea>
        </fieldset>
        <br>
        <fieldset class="center">
            <input type="submit" value="Вступить в клуб">
            <input type="reset" value="Очистить и начать все заново">
        </fieldset>
    </form>

create_user.php
<?php
    require "database_connection.php";
    $first_name = trim($_REQUEST['first_name']);
    $last_name = trim($_REQUEST['last_name']);
    $email = trim($_REQUEST['email']);
    $bio = trim($_REQUEST['bio']);
    $facebook_url = str_replace("facebook.org", "facebook.com", trim($_REQUEST['facebook_url']));
    $position = strpos($facebook_url, "facebook.com");
    if ($position === false) {
        $facebook_url = "http://www.facebook.com/" . $facebook_url;
    }
    $twitter_handle = trim($_REQUEST['twitter_handle']);
    $twitter_url = "http://www.twitter.com/";
    $position = strpos($twitter_handle, "@");
    if ($position ===  false) {
        $twitter_url = $twitter_url . $twitter_handle;
    } else {
        $twitter_url = $twitter_url . substr($twitter_handle, $position + 1);
    }
?>
<?php
    $insert_sql = "INSERT INTO users (first_name, last_name, email, bio, facebook_url, twitter_handle) VALUES ('{$first_name}', '{$last_name}', '{$email}', '{$bio}', '{$facebook_url}', '{$twitter_handle}')";
    mysql_query($insert_sql) or die(mysql_error());
    header("Location: show_user.php");
    exit();    
?>

show_user.php
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="example">Профиль</div>
    <div id="content">
        <div class="user_profile">
            <?php
                require "database_connection.php";

                // Получение ID показываемого пользователя
                $user_id = $_REQUEST['user_id'];

                //  Создание инструкции SELECT
                $select_query = "SELECT * FROM users WHERE user_id = " . $user_id;
                
                $result = mysql_query($select_query);

                if ($result) {
                    $row = mysql_fetch_array($result);
                    $first_name = $row['first_name'];
                    $last_name = $row['last_name'];
                    $bio = $row['bio'];
                    $email = $row['email'];
                    $facebook_url = $row['facebook_url'];
                    $twitter_handle = $row['$twitter_handle'];

                    $twitter_url = "http://www.twitter.com/" . substr($twitter_handle, $position + 1);
                    $user_image = "creation.jpg";
                } else {
                    die("Ошибка обнаружения пользователя с ID {$user_id}");
                }
            ?>

            <h1><?php echo "{$first_name} {$last_name}"; ?></h1>
            <p>
                <img src="<?php echo $user_image; ?>">
                <?php echo $bio; ?>
            </p>
            <p>Duis irure culpa velit nostrud.</p>
            <p class="contact_info">Поддерживайте свазь с <?php echo $first_name; ?></p>
            <ul>
                <li><a href="<?php echo $email; ?>">По Электронной почте</a></li>
                <li><a href="<?php echo $facebook_url; ?>">посещение его страницы на Facebook</a></li>
                <li><a href="<?php echo $twitter_url; ?>">отслеживания его сообщений в Twitter</a></li>
            </ul>
        </div>
    </div>
</body>
</html>

Warning: Cannot modify header information - headers already sent by (output started at C:\OSPanel\domains\localhost\scripts\create_user.php:1) in C:\OSPanel\domains\localhost\scripts\create_user.php on line 24

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2019-02-18
@nehmet_b

before sending headers, NOTHING should be sent to the output, that is, the first lines of the response should be headers. So either you have some kind of output before calling the header (it can be not only echo, but also a warning output) or the file itself has the wrong encoding, which causes extra characters to be output when the script starts (check that the encoding must be UTF- 8 without BOM).

V
Vitsliputsli, 2019-02-18
@Vitsliputsli

Warning: Cannot modify header information - headers already sent by (output started at C:\OSPanel\domains\localhost\scripts\create_user.php:1)

I translate: you can not change the header information (header), because headers have already been sent.
As soon as you send something to the output (even a space), the headers will be formed and sent immediately: before the headers are sent, you should not have a single character outside the php tags.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question