我对 PHP 相当陌生,我正在尝试将用户的输入保存到 mysql 数据库中。我按照在线教程进行了操作,但是每次输入用户信息时,网站都会告诉我它失败了。我唯一能想到的是主机名(我从 phpadmin 复制并粘贴了它)。如果有什么问题,请告诉我。
联系人.html
<section id="mid_section">
<div id="boxes">
<h1>
Leave your information here for a quick reponse:
</h1>
<br/>
<form id="myform" action="userinfo.php" method="post">
Name:<input type="text" value="name">
Email:<input type="email" value="email">
Phone:<input type= "tel" value="phone(opt)">
<button id="sub">Submit</button>
</form>
数据库.php
<?php
$conn = mysql_connect('custsql.eigbox.net','username','password');
$db= mysql_select_db('visitors');
?>
用户信息.php
<?php
include_once('db.php');
$name =$_POST['name'];
$email =$_POST['email'];
$phone =$_POST['phone'];
if(mysql_query("INSERT INTO users (name,email,phone) VALUES ('$name','$email','$phone')"))
echo"successfully inserted";
else
echo "failed";
?>
myscript.js
$("#sub").click(function(){
$.post($("#myform").attr("action"), $("#myform:input").serializeArray(), function(info){$("#result").html(info);});
});
$("#myform").submit(function(){
return false;
});