Database Connection to live site

2019-08-08 19:13发布

问题:

I'm currently building an online booking form as a project and once the user hits the submit button it sends an email with the details to a specified email and stores everything in an database. Currently this is all working fine and well on a localhost set up.

I have a domain name with a current live website and when i upload this new website as an extra page it still preforms the sending of the email but won't load anything into my database.

I'm almost certain it's because my php script for the email/database is specifying localhost as the DB connection but how do i go about connecting it if i was to upload the webpage to my live domain.

Any help is appreciated :)

回答1:

Ask service provider for username and password and export sql file and upload then,ask them for run sql file and then try to connect database live.

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>