私はconfigファイルの正しいアドレスをバインドし、mysqlをリモートサーバに接続する方法を理解するという厳しいプロセスを経ました。昨日は別のコードで作業していましたが、今は接続していません。私はダイを「接続に失敗しました:」と言っていますが、私がconnect_errorを表示していないので、そのようなことはできません。誰かが自分のコードに間違ったことを見ていますか?注:私はこれが安全ではないことを知っています。私は通常、準備されたステートメントを行いますが、dbの問題への接続で作業しようとしています。リモート接続は正しく設定されていますが、PHPコードの接続に失敗していますか?
<?php
$server = "174.---.--.187";
$username = "dylanto";
$pass = "------";
$db = "survey";
//$port = 3306;
//create connection
$conn = new mysqli($server, $username, $pass, $db);
//check connection
if (!$conn->connect_error) {
die("Connection failed: " . $conn->connect_error);}
$user = $_POST['user'];
$pass = $_POST ['pass'];
$sql = "insert into login (user, pass) values ('$user','$pass')";
if ($conn->query($sql)==TRUE) {
echo "Account created";}
else {echo "something went wrong";}
$con->close;
?>
HTMLコード:
<html><head><title>Log-in</title>
<link rel="stylesheet" type="text/css" href="sytle.css"></head>
<body>
<center><u><strong><h2>Login</h2></u></strong></center>
<br />
<center>
<form action="signup_process.php" method="POST">
Pick Username: <br>
<input type ="text" name = "user"><br>
Pick Password:<br>
<input type ="password" name ="pass"><br>
<input type="submit" name="submit" value="Sign-up">
</form></center>
</body>
</html>
'もし(!$ conn-> connect_error){'、これは何も接続エラーがない=削除'! ' – cmorrissey
あなたのコードは、あなたがPDOかmysqliが準備したstamentsを学ぶために必要なSQLインジェクション攻撃にもオープンしています – cmorrissey
あなたはSQLインジェクションのために広くオープンしています。 mysqliを使用しているので、[prepared statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)と[bind_param](http://php.net/ manual/en/mysqli-stmt.bind-param.php)。 **これは発生する可能性のある厄介な引用問題を処理します。** – aynber