为什么我的GET变量没有通过我的函数传递? PHP&库MySQLi

时间:2015-11-08 18:21:05

标签: php function variables get forum

在分配变量$ cid之后,我已经回显了它,并使用正确的值回显了它。但是当传递给函数时它不起作用,它将值0放入数据库中。当我删除变量并只是通过它传递一个随机值时,我传递给函数的任何数字都会被正确地放入数据库。我也尝试在if语句的内部和外部分配值,但它仍然无效。这是代码......

$cid = $_GET['cid'];
if (isset($_POST['submit'])) {
    $title = htmlentities($_POST['title']);
    $desc = htmlentities($_POST['description']);

    $fields = array($title, $desc);
    foreach ($fields as $value) {
        if(empty($value) == true) {
            $errors[] = "Please fill in all of the required fields";
            break 1;
        }
    }

    if (topicExists($title) === true) {
        $errors[] = "Sorry this topic already exists";
    } else {
        if (empty($errors) === true && logged_in() === true) {
            createTopic($title, $desc, $cid);
        }
    }
}

function createTopic($title, $description, $cid) {
    global $user_data;
    global $conn;
    $date = date('Y/m/d');
    $creator = $user_data['userName']; 
    $query = "INSERT INTO topics (topicTitle, topicDesc, topicDate, topicBy, catId, topicPosts, topicLikes) VALUES ('$title', '$description', '$date', '$creator', '$cid', '0', '0')";
    mysqli_query($conn, $query);
}

0 个答案:

没有答案