php - MySQL Database Connection Problems -
i set a database, , made code allowed people register members page on website i'm building. code used has worked before, many times, reason keep getting error message when try submit data test:
failed connect server: lost connection mysql server @ 'reading initial communication packet', system error: 111
i've tried know, nothing works. think i'm missing something, here's php code sends data (however, nothing in code seems wrong or out of place):
<?php session_start(); require_once('config.php'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(db_host, db_user, db_password); if(!$link) { die('failed connect server: ' . mysql_error()); } $db = mysql_select_db(db_database); if(!$db) { die("unable select database"); } function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $fname = clean($_post['fname']); $lname = clean($_post['lname']); $login = clean($_post['login']); $password = clean($_post['password']); $cpassword = clean($_post['cpassword']); if($fname == '') { $errmsg_arr[] = 'first name missing'; $errflag = true; } if($lname == '') { $errmsg_arr[] = 'email'; $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 not match'; $errflag = true; } if($login != '') { $qry = "select * members login='$login'"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'login id in use'; $errflag = true; } @mysql_free_result($result); } else { die("query failed"); } } if($errflag) { $_session['errmsg_arr'] = $errmsg_arr; session_write_close(); header("location: register-form.php"); exit(); } { mkdir("somedirectory//$login") or die ("could not make directory"); } { $ourfilename = "somedirectory/$login/verify.txt"; $ourfilehandle = fopen($ourfilename, 'w') or die("can't open file"); fclose($ourfilehandle); $ourfilename = "somedirectory/$login/name.txt"; $ourfilehandle = fopen($ourfilename, 'w') or die("can't open file"); fclose($ourfilehandle); } { $myfile = "somedirectory/$login.txt"; $fh = fopen($myfile, 'w') or die("can't open file"); $stringdata = "$login\n"; fwrite($fh, $stringdata); fclose($fh); } { $file = '000001.php'; $newfile = "somedirectory/$login/$login.php"; if (!copy($file, $newfile)) { echo "failed copy $file...\n";} } $qry = "insert members(firstname, lastname, login, passwd) values('$fname','$lname','$login','".md5($_post['password'])."')"; $result = @mysql_query($qry); if($result) { header("location: register-success.php"); exit(); }else { die("query failed"); } ?>
any ideas causing mysql connection error?
system error 111 econnrefused, there isn't listening on specified host; either host incorrect or mysql isn't running on it.
Comments
Post a Comment