dongshu7162 2015-07-04 10:25
浏览 47

如何将函数放入变量PHP?

I'm writing a code form my project but i have a problem. I need to put one functions result inside variable and print the result in the database. But see my problem:

My simple file write results from form:

<?php

include '../functions.php';
sec_session_start();

include '../run_conn.php';


if(isset($_POST['submit'])) {


    $publisher = $_POST['publisher']; //THE PROBLEM IS HERE!!! 

    $title = $_POST['title'];
    $tag = $_POST['tag'];
    $type = $_POST['type'];

    $text = $_POST['text'];

    $query = 'INSERT INTO `posts` (`publisher`, `title`, `tag`, `type`,  `text`) VALUES (?,?,?,?,?)';
    //inserisco l'id utente ovunque

    //
    $params = array($publisher, $title, $tag, $type, $text);

    /* $id_usr_1 = $_POST['id_usr_1'];
    $id_usr_2 = $_POST['id_usr_2'];
    $text = $_POST['text'];



    $query = 'INSERT INTO `chat_t3` (`id_usr_1`, `id_usr_2`, `text`) VALUES (?,?,?)';
    //inserisco l'id utente ovunque

    //
    $params = array($id_usr_1, $id_usr_2, $text);
    */
    $results = dataQuery($query, $params);

    // for testing only
    echo 1 == $results ? 'Ok ' : 'fallito';
}
if ($results == true){
header('location: ../../admin/users.php');
echo 'Tutto fatto, ora puoi eseguire tornare alla schermata precedente!';
} else {
}

?>

Now I need to know how to transform $publisher = $_POST['publisher']; to $publisher = echo get_talkm3_email(); .

But probably I can't do this because when I try to load page it turn blank.

I'm a beginner and I don't know what I'm doing wrong.

The function get_talkm3_email is this:

function get_talkm3_email () {
    include 'db_connect.php';

    $conn = $mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
    
    $query = "SELECT email FROM users WHERE email = '{$_SESSION['email']}'";
    $result = $conn->query($query);

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            echo $row["email"];

        }
    } else {
        echo "Si è verificato un errore, non ho trovato nulla";
    }
    }

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?