How to connect my php code to sql

how to connect my php code to sql

this is my code where is the problem??? ,is the localhost name is true
i am abeginner and this is my first try in php and sql

<?php mysql_connect("localhost","id4039687_belal","0775906095") or die(mysql_error()); mysql_select_db("id4039687_users")or die(mysql_error()); $name=$_post['name']; $country=$_post['country']; $text=$_post['text']; $query = mysql_query("insert into com(name,country,text) value($name,$country,$text)")or die(mysql_error()); if ($query) { echo "ok"; }else { echo "error"; } ?>

If you wana use mysql(); then you have to downgrade your PHP version to 5.6
cPanel>Settings>General

this is not my problem ,my problem in the host name should i put local host but idont know the local host name to the website

localhost is correct :slight_smile:

I put the localhost, username and password all correct
When I make run to the program on my computer it works without any problems, but when i uploaded it to another website it didn’t work at all
Where is the problem could be???
Thanks…

Try using this code

<?php
if(mysqli_connect('localhost','DBUSER','DBPASS','DBNAME')){
echo "Connected";
}else{
echo "failed";
}
1 Like

Thank you and apologize for bothering you