Jump to content

mysql_connect() error - Help please


1acid

Recommended Posts

Hi there, I am new, like fresh meat new  :o 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

 

Link to comment
https://forums.phpfreaks.com/topic/265719-mysql_connect-error-help-please/
Share on other sites

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.