1acid Posted July 15, 2012 Share Posted July 15, 2012 Hi there, I am new, like fresh meat new if anyone minds helping me, Id really appreciate it. I had a look around for a few similar thread i pinged my localhost through command promt and everything was fine(as far as Im aware) so the error im getting is : Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\Program Files\EasyPHP-12.0\www\init.php on line 5 Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\Program Files\EasyPHP-12.0\www\init.php on line 5 The file init.php contains the following code: <?php include_once('config.php'); mysql_connect('DB_HOST', 'DB_USER', 'DB_PASS'); mysql_select_db('DB_NAME'); ?> the file config.php contains the following code: <?php $config["DB_HOST"] = 'localhost'; $config["DB_HOST"] = 'root'; $config["DB_PASS"] = ''; $config["db_NAME"] = 'craig'; ?> This is my actual file that is meant to add data to my database: <?php include_once('init.php'); if(isset($_POST['title'],$_POST['post'])){ mysql_query("INSERT INTO posts SET title = '{$_POST['title']}', contents = '{$_POST['post']}'"); } ?> <!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>Untitled Document</title> <style type="text/css"> label{display:black;} </style> </head> <body> <div id ="main"> <form method ="post" action=""> <div> <label for="title"><br/>Title</lable> <input type ="text" name="title" id="title"/> </div> <div> <lable for="post"><br/>Post</label> <textarea name ="text" id="post" rows="15" cols="50"></textarea> </div> <div> <input type="submit" value="Post"/> </div> </form> </div> </body> </html> Am i being stupid? Im not very experienced with this stuff and im trying to follow along to a youtube series and learn a bit more. please any help is greatly appreaciated. Thanks 1acid Quote Link to comment https://forums.phpfreaks.com/topic/265719-mysql_connect-error-help-please/ Share on other sites More sharing options...
bleured27 Posted July 15, 2012 Share Posted July 15, 2012 try this <?php $host = 'localhost'; // Server Host Name $user = 'root'; // Server User Name $password = ''; // Server Password $db = 'test'; // Your Database $link = mysql_connect($host,$user,$password) or die('Error in Server information'); mysql_select_db($db,$link) or die('Can not Select Databasse'); ?> include this totaly and do your scripts between tags Quote Link to comment https://forums.phpfreaks.com/topic/265719-mysql_connect-error-help-please/#findComment-1361722 Share on other sites More sharing options...
1acid Posted July 15, 2012 Author Share Posted July 15, 2012 Thanks for the reply, that has removed the connect error message but now when i click the submit button it doesnt actually dd the data to the data base? Could you or anyone assist me with that maybe? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/265719-mysql_connect-error-help-please/#findComment-1361727 Share on other sites More sharing options...
Pikachu2000 Posted July 15, 2012 Share Posted July 15, 2012 $_POST['post'] doesn't exist in your $_POST array; there is no form element with that name. Because of that, the conditional will never be TRUE, and the query will never be executed. Quote Link to comment https://forums.phpfreaks.com/topic/265719-mysql_connect-error-help-please/#findComment-1361729 Share on other sites More sharing options...
1acid Posted July 15, 2012 Author Share Posted July 15, 2012 ok, so where i have this <form method ="post" action=""> should i be naming this form post? Im sorry im kinda new and tryna wrap my head around all of this. thanks for the reply again. OTherwise how would I make post exist in my $_POST array? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/265719-mysql_connect-error-help-please/#findComment-1361732 Share on other sites More sharing options...
Pikachu2000 Posted July 15, 2012 Share Posted July 15, 2012 You should first make sure the form has been submitted with if( strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) {, then validate that each field you want to require has something entered in it, by first trimming any leading/trailing whitespace from it, then making sure it's not empty. Quote Link to comment https://forums.phpfreaks.com/topic/265719-mysql_connect-error-help-please/#findComment-1361734 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.