我想我已经做好了一切。这一定是个愚蠢的错误。我已经设置了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>
答案 0 :(得分:0)
您必须将mysqli_select_db
用于要添加记录的select数据库。
<?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();
}
// ...some PHP code for database "my_db"...
// Change database to "test"
mysqli_select_db($con,"test");
// ...some PHP code for database "test"...
mysqli_close($con);
?>