0

I have this code to insert data into a MySQL Database.

<?php
$con = mysqli_connect('mysql4.000webhost.com', 'a9671143_cas', '08011998', 'a9671143_testdb');
$number = $_POST['number'];
$name = $_POST['name'];
$password = $_POST['password'];
$partiesIds = $_POST['partiesIds'];

$statement = mysqli_prepare($con, 'INSERT INTO User (number, name, password, partiesIds) VALUES (test, test, test, test)');
mysqli_execute($statement);

mysqli_stmt_close($statement);

    mysqli_close($con);
?>

And I get this: enter image description here

What's wrong, I got this code from a tutorial so I don't understand it well.

4
  • Read the errors, they are extremely valuable: "Access denied for user...". This means that the username and / or password you tried to use in your mysqli_connect statement are incorrect. (The subsequent errors are a result of not being connected successfully, so don't yet factor in to the issue). Commented Jan 13, 2016 at 2:48
  • It seems there is some issue with username or password from the screenshot. May be there is no password in your localhost. Please check once again. Commented Jan 13, 2016 at 2:49
  • @cale_b , But it is right, that's the point. D; Commented Jan 13, 2016 at 3:11
  • So it wasnt right, was it? I did point you in the correct direction. (At least according to the answer you accepted). Commented Jan 13, 2016 at 15:13

1 Answer 1

1

Correct this line : $con = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db'); Your host/name/password or db name is not correct.

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

4 Comments

Should it be $con = mysqli_connect('mysql4.000webhost.com', 'a9671143_cas', '08011998', 'a9671143_testdb');? The password is right, I just changed it. So is the user.
Have you created access from your user to your db?
What do you mean by access to my db?
Often when I make a db, I make user than make db. Not directly make user and db in once time. So, when you make your db, is it correct way? If so, test your setting with code like here if($con)echo "Success Connect"; //if not showing Success Connect, your setting of DB is wrong

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.