Jump to content

Recommended Posts

I am getting the following errors. Do I need to include a connection string even if I already have a working connection string in with my "require" lines. I manually created an account and can login successfully.  I am trying to build the login page.

This is the error I am getting.

 

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) ... on line 128. Line 128 is this line from below:

 

if(mysql_num_rows(mysql_query("SELECT username FROM logon_information WHERE username = '$username'")) > 0 )

 

Thank you for your help.

 

 

<?php

require("../functions/conf.php");
require("../functions/dbConnect.php");     

?>

<?
            
echo '<h3>Sign up</h3>';   
  
if($_SERVER['REQUEST_METHOD'] != 'POST')   
{   
    
THIS IS THE FORM SECTION, I REMOVED ALL THE FIELDS TO SIMPLIFY THIS.
    
}  
else  
{  
    
    $errors = array(); /* declare the array for later use */  
  
    if(isset($_POST['username']))   
    {   
        //the user name exists   
        if(!ctype_alnum($_POST['username']))
        {   
            $errors[] = 'The username can only contain letters and digits.';
        }
        if(strlen($_POST['username']) > 30)
        {
            $errors[] = 'The username cannot be longer than 30 characters.';   
        }   
    }   
    else  
    {   
        $errors[] = 'The username field must not be empty.';   
    }   
  
    if(isset($_POST['password']))   
    {   
        if($_POST['password'] != $_POST['user_pass_check'])   
        {   
            $errors[] = 'The two passwords did not match.';   
        }   
    }   
    else  
    {   
        $errors[] = 'The password field cannot be empty.';   
    }   

    if(!empty($errors)) /*check for an empty array, if there are errors, they're in this array (note the ! operator)*/  
    {   
        echo 'Test Note: Fields are not filled in correctly..';  
        echo '<ul>';  
        foreach($errors as $key => $value) /* walk through the array so all the errors get displayed */  
        {  
            echo '<li>' . $value . '</li>'; /* generates error list */  
        }  
   echo '</ul>';  
  }  
  else  
  {  


if(mysql_num_rows(mysql_query("SELECT username FROM logon_information WHERE username = '$username'")) > 0 ) { 
   echo "Username is already in use";} else {
   $query_user = "INSERT INTO logon_information (userUID, username, password) 
     VALUES ('$userUID', '$username', sha1('$password'))";
   
   $query_userDetails = "INSERT INTO user_information (userUID, firstName, middleInitial ,lastName, emailAddress, companyName, submitToName, submitToEmail) 
     VALUES ('$userUID', '$firstName', '$middleInitial' ,'$lastName', '$emailAddress', '$userUID', '$companyName', '$submitToName', '$submitToEmail')";
   
   $results = mysql_query($query_user) or die 
   ("Could not execute query : $query_user." . mysql_error());
   $results = mysql_query($query_userDetails) or die 
   ("Could not execute query : $query_userDetails." . mysql_error()); 
   }
   if ($results)   
        {   
            //display the error   
            echo 'Test message:  Error during account creation.  Do something about it.';  
            //echo mysql_error(); //debugging purposes, uncomment when needed  
        }  
        else  
        {  
            echo 'Successfully registered. You can now sign in!';  
        }  
    }  
}  
   
?>

Link to comment
https://forums.phpfreaks.com/topic/201438-phpmysql-connection-issue/
Share on other sites

Would it help if I posted the dbconnect.php?  I am stumped so if you have any ideas I am open to trying them.

 

<?

function db_connect($hostname, $database, $username, $password)
{
try {
	$connection = new PDO('mysql:host=' . $hostname . ';dbname=' . $database . ';', $username, $password);
	return $connection;
} catch (PDOException $e) {
	echo 'Connection failed: ' . $e->getMessage();
}
}

?>

Ok, I am working to get the PDO methods integrated.  I am trying to identify which object is the non-object.  I know the query itself works.

 

I get this error:

Fatal error: Call to a member function exec() on a non-object

 

From this line:

$namecheck = $db_connect->exec("SELECT username FROM logon_information WHERE username = '$username'");

 

$db_connect is my connection string in my dbconnect.php file.  See below:

<?

function db_connect($hostname, $database, $username, $password)
{
try {
	$connection = new PDO('mysql:host=' . $hostname . ';dbname=' . $database . ';', $username, $password);
	return $connection;
} catch (PDOException $e) {
	echo 'Connection failed: ' . $e->getMessage();
}
}

?>

 

Thank you

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.