sella2009 Posted January 1, 2010 Share Posted January 1, 2010 I try to connect to mysql but it doesnt work and I get this error "Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'DB_HOST' (11004) in C:\xampp\htdocs\project\project\index.php on line 35 Could not connect to DB_HOST" Here is the code for my index. php <?php require("smarty/Smarty.class.php"); require("intouch.lib.php"); require("intouch.cfg.php"); /* Set version info */ define("INTOUCH_VERSION","v0.5.1 Alpha"); /* Open the DB connection */ mysql_connect(DB_HOST,DB_USER,DB_PASS) or die("Could not connect to ".DB_HOST); mysql_select_db(DB_NAME) or die("Could not select database ".DB_NAME); /* Starting the session */ session_start(); /* Register session and init if it does not exist */ if(!session_is_registered("session")) { session_register("session"); /* Initalize the session */ login_reset(); } if(isset($session['action'])&&!isset($action)) $action = $session['action']; elseif(isset($action)) $session['action'] = $action; $index = new Smarty; $error = NULL; /* Logout => Reset the session */ if($action=="logout") { login_reset(); $error = OK_LOGGED_OUT; $action = "login_show"; } /* Let's do some authentification here */ if($action=="login_verify") { if($session["userid"] = login_verify($user,$password)) { $action = "addr_list_show"; $session["logged_in"] = true; } else { $action = "login_show"; $error = ERR_INV_AUTH; } } /* Deciding what to do... */ switch($action) { case "gb_show": $session["logged_in"] ? gb_show($page) : login_show(ERR_LOGIN_REQ); break; case "gb_sign_show": $session["logged_in"] ? gb_sign_show() : login_show(ERR_LOGIN_REQ); break; case "gb_sign_insert": if($session["logged_in"]) { gb_sign_insert($text); gb_show(0); } else login_show(ERR_LOGIN_REQ); break; case "gb_del": $session["logged_in"] ? gb_del($gbid,$conf) : login_show(ERR_LOGIN_REQ); break; case "addr_list_show": $session["logged_in"] ? addr_list_show($nalpha,$classid,$order) : login_show(ERR_LOGIN_REQ); break; case "addr_user_show": $session["logged_in"] ? addr_user_show($userid) : login_show(ERR_LOGIN_REQ); break; case "addr_user_edit": $session["logged_in"] ? addr_user_edit($userid) : login_show(ERR_LOGIN_REQ); break; case "addr_user_update": $session["logged_in"] ? addr_user_update($user) : login_show(ERR_LOGIN_REQ); break; case "addr_user_del": $session["logged_in"] ? addr_user_del($userid,$conf) : login_show(ERR_LOGIN_REQ); break; case "addr_toggle_admin": $session["logged_in"] ? addr_toggle_admin($userid,$admin,$nalpha,$classid,$order) : login_show(ERR_LOGIN_REQ); break; case "new_account_show": new_account_show(); break; case "new_account_insert": if(new_account_insert($account)) login_show(OK_ACCOUNT_CREATED); break; case "login_show": default: login_show($error); break; } $index->assign("intouch_version",INTOUCH_VERSION); $index->display("index.tpl"); /* Close DB connection */ mysql_close(); ?> and here is the code for my intouch.cfg.php <? /* database settings */ define("DB_USER","project"); define("DB_PASS","123456"); define("DB_NAME","project"); define("DB_HOST","localhost"); /* guestbook settings */ define("GB_ENTRIES_PER_PAGE",10); define("GB_ALLOW_HTML",true); /* error messages */ define("ERR_INV_AUTH","Invalid user or password!"); define("ERR_LOGIN_REQ","You need to login before you can do this!"); define("ERR_MISS_FIELDS","Some required fields are not filled. Check your submission!"); define("ERR_PASSES_DONT_MATCH","The two passwords don't match!"); define("ERR_USR_NOT_UNIQUE","Your username does already exist! Choose another one..."); define("ERR_UNABLE_CREATE_ACCOUNT","Wired, I was unable to create a new account, contact your sysadmin blah, blah..."); /* success messages */ define("OK_ACCOUNT_CREATED","Your account has been successfully created! Login now..."); define("OK_LOGGED_OUT","Successfully logged out!"); ?> I have entered the right password and everything and it seems like its not working and I still get that error, can anyone here please help???????? Link to comment https://forums.phpfreaks.com/topic/186857-i-cant-connect-with-mysql/ Share on other sites More sharing options...
Mchl Posted January 1, 2010 Share Posted January 1, 2010 Are short tags (<? ) enabled on your server. Anyway, you should use <?php, so try changing <? to <?php Link to comment https://forums.phpfreaks.com/topic/186857-i-cant-connect-with-mysql/#findComment-986787 Share on other sites More sharing options...
sella2009 Posted January 1, 2010 Author Share Posted January 1, 2010 Are short tags (<? ) enabled on your server. Anyway, you should use <?php, so try changing <? to <?php Thanks so much man, you sir are the best Link to comment https://forums.phpfreaks.com/topic/186857-i-cant-connect-with-mysql/#findComment-986789 Share on other sites More sharing options...
Mchl Posted January 1, 2010 Share Posted January 1, 2010 That's what she said! XD Link to comment https://forums.phpfreaks.com/topic/186857-i-cant-connect-with-mysql/#findComment-986791 Share on other sites More sharing options...
sella2009 Posted January 1, 2010 Author Share Posted January 1, 2010 That's what she said! XD than you mchl Link to comment https://forums.phpfreaks.com/topic/186857-i-cant-connect-with-mysql/#findComment-986793 Share on other sites More sharing options...
Mchl Posted January 1, 2010 Share Posted January 1, 2010 Link to comment https://forums.phpfreaks.com/topic/186857-i-cant-connect-with-mysql/#findComment-986794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.