致命错误:函数名称必须是第7行的C:\ wamp \ www \ smith \ config.php中的字符串 [英] Fatal error: Function name must be a string in C:\wamp\www\smith\config.php on line 7

查看:83
本文介绍了致命错误:函数名称必须是第7行的C:\ wamp \ www \ smith \ config.php中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试注册会员时遇到错误.表单无法连接到数据库.错误:致命错误:函数名称必须是第7行C:\ wamp \ www \ smith \ config.php中的字符串
第7行以粗体突出显示,我也遇到错误:
拒绝访问locahost(史密斯")
多谢您的协助.

我的表格代码如下:

Hi I have an error when trying to register a member. The form is failing to connect to the database. Error:Fatal error: Function name must be a string in C:\wamp\www\smith\config.php on line 7
Line 7 has been highlighted in bold and I am also getting an error:
Access denied to locahost ("smith")
I will appreciate your assistance.

THE CODE FOR MY FORM IS BELOW:

<?php
    //Start session
    session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect($localhost, $username, $password);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db("smith");
    if(!$db) {
        die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

    //Sanitize the POST values
    $fname = clean($_POST['fname']);
    $lname = clean($_POST['lname']);
    $login = clean($_POST['login']);
    $password = clean($_POST['password']);
    $cpassword = clean($_POST['cpassword']);

    //Input Validations
    if($fname == '') {
        $errmsg_arr[] = 'First name missing';
        $errflag = true;
    }
    if($lname == '') {
        $errmsg_arr[] = 'Last name missing';
        $errflag = true;
    }
    if($login == '') {
        $errmsg_arr[] = 'Login ID missing';
        $errflag = true;
    }
    if($password == '') {
        $errmsg_arr[] = 'Password missing';
        $errflag = true;
    }
    if($cpassword == '') {
        $errmsg_arr[] = 'Confirm password missing';
        $errflag = true;
    }
    if( strcmp($password, $cpassword) != 0 ) {
        $errmsg_arr[] = 'Passwords do not match';
        $errflag = true;
    }

    //Check for duplicate login ID
    if($login != '') {
        $qry = "SELECT * FROM members WHERE login='$login'";
        $result = mysql_query($qry);
        if($result) {
            if(mysql_num_rows($result) > 0) {
                $errmsg_arr[] = 'Login ID already in use';
                $errflag = true;
            }
            @mysql_free_result($result);
        }
        else {
            die("Query failed");
        }
    }

    //If there are input validations, redirect back to the registration form
    if($errflag) {
        $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        session_write_close();
        header("location: register-form.php");
        exit();
    }

    //Create INSERT query
    $qry = "INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','".md5($_POST['password'])."')";
    $result = @mysql_query($qry);

    //Check whether the query was successful or not
    if($result) {
        header("location: register-success.php");
        exit();
    }else {
        die("Query failed");
    }
?>



数据库连接代码:




TH DATABASE CONNECTION CODE:


<?php
        //Database connection
    $mysql_hostname="localhost";
    $mysql_username="root";
    $mysql_password="";
  $mysql_databse="smith";
  $db_mysql_connect($mysql_hostname, $mysql_username, $mysql_password)
  or die("Can not connect to the database");

  mysql_select_db("smith") or die(mysql_error());
?>

推荐答案

errmsg_arr = array(); // 验证错误标志
errmsg_arr = array(); //Validation error flag


errflag = false; // 连接到mysql服务器
errflag = false; //Connect to mysql server


链接 = mysql_connect(
link = mysql_connect(


这篇关于致命错误:函数名称必须是第7行的C:\ wamp \ www \ smith \ config.php中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆