mark103 Posted September 20, 2008 Share Posted September 20, 2008 Hi guys Please can you help me, I am having trouble with my login page on my website. When I input the username and password, it said that it can't connect to local MySQL server through socket. Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/mark107.awardspace.com/login/login-exec.php on line 15 Failed to connect to server: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) why did i get this error?? Please help!!!!!!!!!!! Thanks, Mark Quote Link to comment Share on other sites More sharing options...
nitation Posted September 20, 2008 Share Posted September 20, 2008 Show your code please. How do you connect to your database. Quote Link to comment Share on other sites More sharing options...
mark103 Posted September 21, 2008 Author Share Posted September 21, 2008 Here it is: <?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(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); 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 $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> Do I have to input the correct username and password of my web host on my login php?? Also please can you confirm where mysql database should be local on that the login-exec.php want to get access to the database. Thanks, Mark Quote Link to comment Share on other sites More sharing options...
yrstruly Posted September 21, 2008 Share Posted September 21, 2008 Hallo Can anybody help me, i need to insert a code (sql) which wil check if the user has putt in the correct details. If i put this code into my login code, the sql code appears in the web page, can anybody tell em what am i doing wrong and what will be the best way to do this? Any help will be deeply appreciated. the code follows... <?php require_once("header.html"); ?> <?php require_once('config.php'); if ($_POST['username'] != '' && $_POST['passwd'] != ''){ $user = $_POST[username]; $password = $_POST[passwd]; $sql = "SELECT * from vehicle WHERE VE_Reg_Number = '$user' and VE_Password= '$password'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); $num_rows = mysql_num_rows($result); if (!$num_rows){ $errormessage = "Incorrect username OR password, please try again"; } else{ $_SESSION['veid'] = $user; $_SESSION['id'] = $row[VE_ID]; header("location:ptransactions.php"); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>LOG BOOK TRACKER</title> <link href="file:///C|/Documents and Settings/Anthony/Local Settings/Temporary Internet Files/Content.IE5/U2TC5HJO/styles/admin.css" rel="stylesheet" /> </head> <body> <form id="form1" name="form1" method="post" action=""> <table width="200" align="center"> <tr > <td colspan="2"><div align="center"><strong>TRACKING LOGIN</strong></div></td> </tr> <tr align="center" bgcolor="#008DC6"> <td colspan="2" class="header">LOGIN</td> </tr> <tr bgcolor="#EEEEEE"> <td>UserName</td> <td><input type="text" class="text" name="username" id="username" /></td> </tr> <tr bgcolor="#EEEEEE" > <td>PassWord</td> <td><input type="password" class="text" name="passwd" id="passwd" /></td> </tr> <tr bgcolor="#008DC6" > <td align="right"> </td> <td><input type="submit" name="submit" class="button" id="button" value="Submit" /></td> </tr> <tr> <td colspan="2" class="loginbox" ><span class="orangebold"><?php print $errormessage;?></span></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form> </div> <?php require_once("footer.html"); ?> </body> </html> and here is some of the code that would be chekcing if the user enters the correct details, tell me what shoyuld i be changing and hwat should be added, PLEASE HELP! <?php require_once('config.php'); $registration_number = $_REQUEST['username']; $password = $_REQUEST['password']; //Check that password entered is correct and get the clients email address for this vehicle ID $password_query = "SELECT VE_ID FROM `vehicle` WHERE `VE_Reg_Number` = '$registration_number' AND `VE_Password` = md5( '$password' ) " ; echo $password_query; echo "<br>"; if(!$password_result = mysql_query($password_query)) { die("Error with the database. Please try again later"); } if(mysql_num_rows($password_result)== 0) { die("Password is incorrect. Please try again."); } $row = mysql_fetch_assoc($password_result); $Vehicle_ID = $row['VE_ID']; echo "Vehicle id is $Vehicle_ID<br>"; //Get records for this vehicle_id from the $petrol_query = "SELECT `PE_Place` , `PE_Date_Time` , `PE_Total_KM` , `PE_KM_Travelled` , `PE_Litres_Used` FROM `petrol_entries` WHERE `VE_ID` =$Vehicle_ID ORDER BY `petrol_entries`.`PE_Date_Time` ASC "; echo $petrol_query; echo "<br>"; if(!$petrol_result = mysql_query($petrol_query)) { die("Error with the database. Please try again later"); } if(mysql_num_rows($petrol_result)== 0) { die("No records exist"); } while($row = mysql_fetch_assoc($petrol_result)) { $number_of_entries ++; echo "Date: ".$row['PE_Date_Time']." "; echo "Place: ".$row['PE_Place']." "; echo "PE_Total_KM: ".$row['PE_Total_KM']." "; echo "PE_KM_Travelled: ".$row['PE_KM_Travelled']." "; echo "PE_Litres_Used: ".$row['PE_Litres_Used']." "; echo "<br>"; } ?> Quote Link to comment Share on other sites More sharing options...
mark103 Posted September 22, 2008 Author Share Posted September 22, 2008 anyone???????????????? Quote Link to comment 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.