Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP MySQL
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());
?>
Posted 17-Nov-12 6:39am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi
 
The problem seems to be in the database connection code where you made a call to $db_mysql_connect
 
Though its been a while that I coded in PHP but I guess you cann't use $ sign in front of a function name. Also the function to connect to a database is mysql_connect not db_mysql_connect. Check this out http://php.net/manual/en/function.mysql-connect.php[^]
 
so instead of
 
$db_mysql_connect($mysql_hostname, $mysql_username, $mysql_password)
  or die("Can not connect to the database");
 
please do:
 
mysql_connect($mysql_hostname, $mysql_username, $mysql_password)
  or die("Can not connect to the database");
 

 
Regards
Pawan
 
Please mark the answer as accepted solution if it is relevant.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 365
1 Sergey Alexandrovich Kryukov 277
2 OriginalGriff 165
3 George Jonsson 159
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,860
2 CPallini 5,125
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100