0
私はすべてのことを正しく行ったと思います。それは愚かな間違いでなければなりません。私はMySQL接続をセットアップし、セキュリティのために実際の文字列のエスケープを使用しました。私のエラーを指摘してください、それとも別の方法で実行できるのかを教えてください。PHPからMySQLテーブルに投稿されないデータ。私がここで間違っていることを教えてください
また、私のデータベースで送信されたデータを取得し、そのデータを別のXMLファイルまたは電子メールに取得する方法を提案してください。
<?php
//is there a problem in connection?
$link = mysqli_connect("localhost","root","");
if($link == false){
die("error"); }
if(
isset($_POST['name']) &&
isset($_POST['type']) &&
isset($_POST['email']) &&
isset($_POST['website']) &&
isset($_POST['app']) &&
isset($_POST['phone']) &&
isset($_POST['about']))
{
//real escape string is used, is it affecting my data?
$name = mysqli_real_escape_string($link, $_POST['name']);
$type = mysqli_real_escape_string($link, $_POST['type']);
$email = mysqli_real_escape_string($link, $_POST['email']);
$website = mysqli_real_escape_string($link, $_POST['website']);
$app = mysqli_real_escape_string($link, $_POST['app']);
$phone = mysqli_real_escape_string($link, $_POST['phone']);
$about = mysqli_real_escape_string($link, $_POST['about']);
//query has been created
$query = "INSERT INTO `contact_form` (name, type, email, website, app,
phone, about) VALUES ('$name', '$type', '$email', '$website', '$app', '$phone', '$about')";
if(mysqli_query($link, $query)){
echo 'the form has been submitted successfully';
}else{
echo 'there was some problem';
}
}
?>
<!Doctype html>
<html>
<form action="index.php" method="POST">
<h3>Post your startup info</h3>
<ul>
<li><label><span class="glyphicon glyphicon-briefcase"></span></label><input type="text" name="name" placeholder=" startup/business name"></li>
<li><label><span class="glyphicon glyphicon-folder-open"></span></label><input type="text" name="type" placeholder=" startup/business type"></li>
<li><label><span class="glyphicon glyphicon-envelope"></span></label><input type="text" name="email" placeholder=" email address"></li>
<li><label><span class="glyphicon glyphicon-link"></span></label><input type="text" name="website" placeholder=" website link"></li>
<li><label><span class="glyphicon glyphicon-phone"></span></label><input type="text" name="app" placeholder=" app link"></li>
<li><label><span class="glyphicon glyphicon-earphone"></span></label><input type="text" name="phone" placeholder=" phone number"></li>
<li><label><span class="glyphicon glyphicon-pencil"></span></label><textarea name="about" rows="6" placeholder="write about your startup/business in short"></textarea></li>
<li class="startup_submit"><button type="submit"><span class="glyphicon glyphicon-send"></span></button></li>
</ul>
</form>
</html>
データベースを選択してください。あなたのデータベースとして4番目のパラメータを渡してください。http://php.net/manual/en/function.mysqli-connect.php – Saty
mysqli_connectの最後のパラメータであるdb_nameはオプションではないと思います。 –
このreal_escapeのものはすべて気にしないでください。代わりに用意されたステートメントを参照してください – Strawberry