1

i tried this code but i dont work

    <?php

$con=mysqli_connect("localhost","root","","db_insert_txt");

// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else{
echo "rak connecté";
}
$lines = file('test.txt');  
$test = "";  
$insert_string = "INSERT INTO `test_txt`(`test`) VALUES"; 
$counter = 0; 
$maxsize = count($lines); 
foreach($lines as $line => $company) { 
$insert_string .= "('".$company."')"; 
$counter++; 
if($counter < $maxsize){ 
$insert_string .= ","; 
}//if 
}//foreach 
mysqli_query($insert_string) or die(mysqli_error());
mysqli_close($con);
?>

It gives me the following warning:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given

1 Answer 1

1

The error message describes pretty well what's wrong.

You need to pass the DB connection parameter to the query:

mysqli_query($con, $insert_string);

Use it for the following also:

mysqli_error($con);
Sign up to request clarification or add additional context in comments.

4 Comments

it says no Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\wamp\www\update-from-txt\index.php on line 26
@HamaneelMehdi you refuse to do any thinking of your own, that's not nice.
sorry i wont do it agan :/
@HamaneelMehdi you don't need to apologize to me, it's bad for you not me.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.