Php 如何向sql server添加数据
嗨,伙计们,我两个月前就开始创建一个网站了,就在我创建网站的一周前,我就触底了。我的问题是,我无法让它将数据添加到我的SQL数据库中,该数据库是我使用000webhost.com包提供的SQL数据库和phpmyadmin创建的 下面是我的PHP代码,底部是HTML:Php 如何向sql server添加数据,php,html,mysql,sql,Php,Html,Mysql,Sql,嗨,伙计们,我两个月前就开始创建一个网站了,就在我创建网站的一周前,我就触底了。我的问题是,我无法让它将数据添加到我的SQL数据库中,该数据库是我使用000webhost.com包提供的SQL数据库和phpmyadmin创建的 下面是我的PHP代码,底部是HTML: <?php $con=mysqli_connect("mysql11.000webhost.com","xxxxxxxx","xxxxxxxxx","xxxxxxxx"); if (mysqli_connect_errn
<?php
$con=mysqli_connect("mysql11.000webhost.com","xxxxxxxx","xxxxxxxxx","xxxxxxxx");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob@gmail.com', 'gigtit',bob_name)");
echo"adding is done";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Friend It sign up</title>
<link rel="stylesheet" type="text/css" href=" css/bootstrap.css">
<link rel="stylesheet" type="text/css" href=" css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href=" css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href=" css/index.css">
</head>
<body>
<ul class="nav nav-pills">
<li><a href="index.html">Home</a></li>
<li><a href="About.html">About</a></li>
<label class="web-name">Friend It</label>
</ul>
<div class="page-header">
<h1>Sign up</h1>
</div>
<div class="container">
<div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-col-sm-8 col-sm-offset-2">
<div class="panel panel-primary" >
<div class="panel-heading">
<div class="panel-title">Sign up</div>
</div>
<div style="padding-top:30px" class="panel-body" >
<from action="connect.php" method="post">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input id="login-username" name="user" type="text" class="form-control" name="username" value="" placeholder="email">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<input id="login-username" type="text" name="fullname" class="form-control" name="username" value="" placeholder="Full Name">
</form>
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input id="login-password" name="pass" type="password" class="form-control" name="password" placeholder="Password">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-repeat"></i></span>
<input id="login-password" type="password" class="form-control" name="passwordre" placeholder="Re-type Password">
</div>
<div style="margin-top:10px" class="form-group">
<div style="margin-left:140px" class="col-sm-12 controls">
<a id="btn-signup" href="connect.php" class="btn btn-primary" type="submit">Sign up</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
您也可以通过转到来查看该网站。尝试此查询,我认为唯一的问题是名称列的值应该用单引号括起来,但缺少单引号
$mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob@gmail.com', 'gigtit','bob_name')");
希望获得以下帮助:问题出在您的查询中,请尝试以下方法:
$mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob@gmail.com', 'gigtit','bob_name')");
对于您的第二个错误编辑:您将其作为关于错误括号的注释发布 你可以查一下 或者发布导致错误的那一行。函数是mysqli\u query而不是$mysqli\u query,我不知道为什么其他人没有捕捉到这一点
mysqli_query("INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob@gmail.com', 'gigtit', 'bob_name')");
因为它是程序样式,所以可以将连接作为第一个参数传递:
mysqli_query($con, "INSERT INTO userreg (email,password,name)
VALUES ('Peterbaob@gmail.com', 'gigtit', 'bob_name')");
请检查您是否提供了由000webhost生成的相同密码…否则请说明哪里有错误?抱歉,仅此而已mistake@user223784你又一次没有接受我的回答!我尝试了这段代码,但现在我收到了一种新的错误致命错误:函数名必须是第12行/home/a8206989/public_html/connect.php中的字符串。您可以在friendit.net16.net/connect.php上看到此错误