1

I have a block of code to submit my HTML form values to my Database using PHP via XAMPP. After construction and testing the record will saved in database successfully but I see a notice that says below:

Undefined variable: localhost in C:\xampp\htdocs\30-11-2021\processhtml.php on line 19

Kindly see my line 19 below also:

$conn = new mysql ($localhost, $dbusername, $dbpassword, $dbname);

1 Answer 1

1

You want

$conn =  new mysql ('localhost', $dbusername, $dbpassword, $dbname);

The first parameter is the hostname of the server running MySQL. In your case it's 'localhost'.

php warns you when you use an undefined variable, and gives the value null for that variable. In this context, a null hostname defaults to localhost, so that's why your code actually works.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it Worked.

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.