0
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$aa = (isset($_POST['aa'])) ? $_POST['aa'] : false;
$a= (isset($_POST['a'])) ? $_POST['a'] : false;
$b = (isset($_POST['b'])) ? $_POST['b'] : false;
$c = (isset($_POST['c'])) ? $_POST['c'] : false;
$d = (isset($_POST['d'])) ? $_POST['d'] : false;
$e = (isset($_POST['e'])) ? $_POST['e'] : false;
$f = (isset($_POST['f'])) ? $_POST['f'] : false;
$g = (isset($_POST['g'])) ? $_POST['g'] : false;


if ($aa && $c) {



    $query = "INSERT INTO casa
              VALUES ('$aa', '$a', '$b', '$c', '$d', '$e', '$f', '$g', 1);";


    $conexion = mysqli_connect('localhost','hostname','password','data_base');



    $resultado = mysqli_query($conexion, $query);


    if ($resultado) {

        echo 'OK';
    } else if (mysqli_errno($conexion) == 1062) {

        echo 'Duplicado';
    } else {

        echo 'Error';
    }
} else {

    //header("Location: index.html");
       echo 'asad';
}

When I upload all my filles to a web hosting, I compliment all the form and when I send it:

Warning: mysqli_connect(): (HY000/2002): No such file or directory in /home/vol4_2/260mb.net/n260m_21275877/xxxx.260mb.org/htdocs/form.php on line 26 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/vol4_2/260mb.net/n260m_21275877/xxxx.260mb.org/htdocs/form.php on line 30 Error

And line 26 is the connection and line 30 is the mysqli_query

I need some help. thanks!!

6
  • 2
    You didn't check whether the connection went through, so you're passing FALSE as the first parameter to mysqli_query. Check if the parameters to mysqli_connect are correct. Commented Mar 6, 2018 at 12:00
  • print mysqli_connect_error() and see what is the error.. It is unable to connect. php.net/manual/en/function.mysqli-connect.php Commented Mar 6, 2018 at 12:00
  • BTW: Check out the meaning of "SQL injection". Your code is vulnerable to that. Commented Mar 6, 2018 at 12:04
  • I print ` mysqli_connect_error()` and this is the error: Unable to connect to MySQL. Debugging errno: 2002 Debugging error: No such file or directory
    – Ara
    Commented Mar 6, 2018 at 12:17
  • Are you sure, that your database server is up and running on the localhost? Commented Mar 6, 2018 at 12:24

2 Answers 2

0

im not sure if you have changed or renamed your user and password in your db, so that's why your case come from here, so plis check this line

$conexion = mysqli_connect('localhost','hostname','password','data_base');
0

The problem is in your MySQL server on hosting.

If it's shared hosting, pls write ticket to provider with error you're getting: "Unable to connect to MySQL. Debugging errno: 2002 Debugging error: No such file or directory".

If you're using VPS or local server, check that mysql.sock file exist in right path and have write permission.

In my.cnf config file you can correct and check path to mysql.sock file:

[Mysqld]
socket = /tmp/mysql.sock
[Client]
socket = /tmp/mysql.sock

And then restart the server /etc/init.d/mysql restart

Related Question: Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

2
  • i´m using 260mb.net as my hosting. But I don´t what should I change to fix it
    – Ara
    Commented Mar 6, 2018 at 13:36
  • Try to contact with support and show them error you are getting. It depends on hosting settings or connection credentials you are using. Commented Mar 6, 2018 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.