普通网友 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 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧