普通网友 2017-12-03 13:32
浏览 18

PHP语法错误,我是盲人吗? [重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them" dir="ltr">PHP parse/syntax errors; and how to solve them</a>
                            <span class="question-originals-answer-count">
                                (18 answers)
                            </span>
                    </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param" dir="ltr">mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it?</a>
                            <span class="question-originals-answer-count">
                                (1 answer)
                            </span>
                    </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/24028697/how-to-fetch-data-in-php-with-mysqli" dir="ltr">How to fetch data in PHP with MySQLi?</a>
                            <span class="question-originals-answer-count">
                                (3 answers)
                            </span>
                    </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/28903302/mysqli-connection-and-query" dir="ltr">mysqli connection and query</a>
                            <span class="question-originals-answer-count">
                                (2 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-12-03 13:40:15Z" class="relativetime">2 years ago</span>.</div>
        </div>
    </aside>

I got this syntax error saying there is a mistake on line 4, but I can't seem to find it..can you help me?


Parse error: syntax error, unexpected ':', expecting ',' or ')' in C:\XAMPP\htdocs\projekt\ajax.php on line 4

My code:

<?php
if (isset($_POST["key"])) {

    $conn = new mysqli(host:"localhost", username:"root", passwd:"", dbname:"serije_bp");

    $name = $conn->real_escape_string($_POST["naziv"]);
    $opis = $conn->real_escape_string($_POST["opis"]);
    $ocjena = $conn->real_escape_string($_POST["ocjena"]);

    if ($_POST["key"] == "dodajNovu") {
        $sql = $conn->query(query: "SELECT id FROM serije WHERE naziv = '$naziv'");
        if ($sql->num_rows > 0)
            exit("TV serija je vec unesena!");
        else {
            $conn->query(query: "INSERT INTO serija (naziv, opis, ocjena)
                                VALUES ('$naziv', '$opis', '$ocjena')");
            exit("TV serija je uspjesno unesena!");
        }
    }
}

?>

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33725272 2017-12-03 13:37
    关注

    Like the documentation says, simply add parameters without “:“. So please remove “host:“ and so on

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀