使用require .htx文件创建connect.php

"add.htx"

<?php
$servername = "my_server_name";
$username = "my_username";
$password = "my_pwd";
$dbname = "my_db_name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO Drama_Gr (Date, Time, Cont, Temp, Hum, Pres, Rain_Y, Rain_M, Rain, Rain_Rate, Wind, Wind_Dir)
VALUES ('<!--date-->', '<!--time-->',  '<!--ForecastStr--> frc', '<!--outsideTemp-->', '<!--outsideHumidity-->', '<!--barometer-->', '<!--totalRain-->', '<!--monthlyRain-->', '<!--dailyRain-->', '<!--rainRate-->', '<!--windSpeed-->', '<!--windDirection-->bfr')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

run this file with weatherlink and output the result file "add.php"

<?php
$servername = "my_server_name";
$username = "my_username";
$password = "my_pwd";
$dbname = "my_db_name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO Drama_Gr (Date, Time, Cont, Temp, Hum, Pres, Rain_Y, Rain_M, Rain, Rain_Rate, Wind, Wind_Dir)
VALUES ('17/08/16', ' 0:11',  ' Increasing clouds with little temperature change.  frc', '24.6', '52', '1012.6', '291.2', '11.2', '0.0', '0.0', '1.6', 'SSEbfr')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

its ok with this way i create a database with my weather station the problem is i want to give this code to run with weather station and other people from my area and create in to my database tables from other weather station but i don't want to include this code my database connection. i think the correct way is to create a file like "connect.php"

<?php
 $servername = "my_server_name";
$username = "my_username";
$password = "my_pwd";
$dbname = "my_db_name";

mysql_connect($hostname, $username, $password) OR DIE("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);
?>

and call this file like

<?php include("connect.php");?> 

i try to add this code in "add.htx" but get bellow error in "add.php" Connection failed: Access denied for user ''@'localhost' (using password: NO)

why? maybe i think because the file "add.htx" start from weatherlink by local C:\WeatherLink\ but the weatherlink upload this file and convert to "add.php" at server at folder like http://my_website/weather/ ,this folder also include and the file "connect.php"

please any help and if is easy give me the correct code at "add.htx" with the wright way to add at "add.htx"

<?php include("connect.php");?> 

thanks

</div>

Was this what you did?

<?php
Include('connect.php');

$servername = "my_server_name";
$username = "my_username";
$password = "my_pwd";
$dbname = "my_db_name";
......
?>

Php is not running your include('connect. Php') file. Bt then, I think the problem is not with the code. I think the problem is with your privileges. Compare ur server username and password with the ones you defined in your script.

// Connection failed: Access denied for user ''@'localhost' (using password: NO)// pls do check ur privileges

for other people i give the solution first thanks to Script47 (open my eyes and see mysql_* must change to mysqli_*)

second i create i think the better way to call "config.php"

here the fresh change at code "add.htx"

<?php
include("config.php");
include("opendb.php");



$sql = "INSERT INTO Drama_Gr (Date, Time, Cont, Temp, Hum, Pres, Rain_Y, Rain_M, Rain, Rain_Rate, Wind, Wind_Dir)
VALUES ('<!--date-->', '<!--time-->',  '<!--ForecastStr--> frc', '<!--outsideTemp-->', '<!--outsideHumidity-->', '<!--barometer-->', '<!--totalRain-->', '<!--monthlyRain-->', '<!--dailyRain-->', '<!--rainRate-->', '<!--windSpeed-->', '<!--windDirection-->bfr')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}


include("closedb.php");
?>

i create 3 files to connect with db and close the db

"config.php"

<?php
$servername = "my_host_name";
$username = "my_username";
$password = "my_pwd";
$dbname = "_my_database_name";
?>

after i create a script "opendb.php"

<?php
// Create my Weather db connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check my Weather db connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>

and i think is correct to create and script to close a connection when upload data to db ,name this script "closedb.php"

<?php
// close my weather db connection

mysqli_close($conn);
?>

and finally the result to "add.php"

New record created successfully

thanks and i hope this usefull and for others

now the last problem is with this code "add.php" the records update the db rows when refresh this page i create a below script to auto refresh multiple files from weather stations in one page but must this page is open to auto update the new result to db and name this page

"send_db.html"

<html>
<head>
<!-- For ease i'm just using a JQuery version hosted by JQuery- you can download any version and link to it locally -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
 $(document).ready(function() {
     $("#responsecontainer").load("http://www.dramaweather.gr/weather2/uploadwl/mysql/add.php");
   var refreshId = setInterval(function() {
      $("#responsecontainer").load('http://www.dramaweather.gr/weather2/uploadwl/mysql/add.php?randval='+ Math.random());
   }, 900000);
   $.ajaxSetup({ cache: false });
});
</script>
    <script>
 $(document).ready(function() {
     $("#responsecontainer").load("http://www.dramaweather.gr/weather2/uploadwl/mysql/add_Serres.php");
   var refreshId = setInterval(function() {
      $("#responsecontainer").load('http://www.dramaweather.gr/weather2/uploadwl/mysql/add_serres.php?randval='+ Math.random());
   }, 900000);
   $.ajaxSetup({ cache: false });
});
</script>
</head>
<body>
 
<div id="responsecontainer">
</div>
</body>
    </html>

is any other way to send the results of "'add.htx" to db auto every 10 minutes without a code from "send_db.html" ;

thanks again for the first problem if anyone know and my for my second problem the solution please help

</div>