Add Data in MySQL Database with PHP Script


Hey guys,

iam a beginner in programming and i start to write my first PHP Script for LogIn and adding Values in MySQL Database (add_data.php). The LogIn works fine but the script is not able to add some Values in my Database. I use the following SQL Function “INSERT INTO” to put my Values in the Database. For example:
$sql = “INSERT INTO customer (name, surname, email) VALUES (‘tom’, ‘tom123’, ‘tom321@gmx’)”;

It didn’t work 

While iam loged in at PHPMyAdmin at 000webhost and select my Database as well as my table (customer), click on SQL and execute the same function as above, the values are added.

The SQL Function seems to be ok because it works, if you execute them over the Webpage, but where is the Problem to execute the same function over the PHP Script??? Is it not allowed to create databases, tables or adding values with an external script?

Please Help me to understand whats going wrong. Sorry for my English…I hope you understand my problem.



Hi @NightHawk1981

Welcome to 000webhost forum!

Can you post your whole code here?


  • You have to connect your database first… Link
  • Then query your database (Insert the data) Link


Hy Supun,

thank you so much!!! The second Link (insert the data) helps me a lot.

I had a Little mistake in my Login function…ang get a wrong return such as “Login Succesfull” but it was “Not sucessfull”…i double checked the hole PHP Script, found my mistake and fixed it. Now it works perfect :smiley: :smiley: :smiley:



Nice to see your problem is solved :smile:

Feel free to open new topic if you have any other questions. Happy web mastering! :wink: