downat420 Posted May 12, 2010 Share Posted May 12, 2010 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!'; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201438-phpmysql-connection-issue/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2010 Share Posted May 12, 2010 You would need to determine why your connection that is being attempted in the dbConnect.php file is either not working or is being closed before the mysql_query() statement. Quote Link to comment https://forums.phpfreaks.com/topic/201438-phpmysql-connection-issue/#findComment-1056868 Share on other sites More sharing options...
downat420 Posted May 12, 2010 Author Share Posted May 12, 2010 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(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201438-phpmysql-connection-issue/#findComment-1056910 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2010 Share Posted May 12, 2010 Ummm. You are creating an instance of the PDO class. You must use methods of the PDO class in your code. Quote Link to comment https://forums.phpfreaks.com/topic/201438-phpmysql-connection-issue/#findComment-1056914 Share on other sites More sharing options...
downat420 Posted May 12, 2010 Author Share Posted May 12, 2010 I see, I am working on integrating the PDO code now. Thank you for the direction. Quote Link to comment https://forums.phpfreaks.com/topic/201438-phpmysql-connection-issue/#findComment-1057268 Share on other sites More sharing options...
downat420 Posted May 13, 2010 Author Share Posted May 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201438-phpmysql-connection-issue/#findComment-1057540 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.