このHTMLを考えると:
<input type="text" class="form-control" name="link" rows="3" action="add2.php" method="post" placeholder="link here">
まずそのURLをエンコードしてからに送信します。 add2.php
.
add2.php
以下のとおりであります:
<?php
$url=$_GET["linki"];
include("../db.php");
$url=$_GET["linki"];
$html = file_get_contents("$url");
preg_match("/<meta property="og:image" content="(.*?)" />/", $html, $matches);
preg_match("/<title>(.*)</title>/i", $html, $title);
$pdo -> exec("INSERT INTO `postss`(`link`) VALUES ("$w")");
?>
URLを埋めようとすると、サーバーが "fordinended error"と応答します。
回答:
回答№1は0これを短くするには:あなたの例は有効なHTMLフォームを示さず、あなたの質問はあなたがあなたのコードで達成しようとしていることを反映していません。
これはあなたに出発点を与えるかもしれません。
HTMLフォーム:
<form action="add2.php" method="POST">
<input type="text" name="link" class="form-control" placeholder="Link here">
<input type="submit" name="submit" class="btn btn-default" value="Submit">
</form>
add2.phpを処理します(コードの機能自体を確認できないため、Qの中から部分的にコピー/貼り付けします)。
<?php
include("../db.php");
if (isset($_POST["submit"]))
{
$link = $_POST["link"];
$html = file_get_contents($link);
preg_match("/<meta property="og:image" content="(.*?)" />/", $html, $matches);
preg_match("/<title>(.*)</title>/i", $html, $title);
$pdo->exec("INSERT INTO `postss`(`link`) VALUES ("$link")"); // Homework: SQL Injection, read up on it. This is still vulnerable.
}
「自分がしたことは何も使用していないことに注意してください。あなたの元の質問のどちらかの中に入ってきた内容は...上のコードの半分は単に役に立たず、残りの半分はSQLインジェクションについて読む必要があります。フォームの送信と処理を始めましょう。