大家好,我 2 个月前开始创建网站,就在一周前,我在制作过程中跌至谷底。我的问题是我无法将数据添加到我使用 000webhost.com 包中提供的 SQL 数据库和 phpmyadmin 创建的 SQL 数据库。
这是我的 PHP 代码,底部有 HTML:
<?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>
您也可以转到 friendit.meximas.com 查看该网站。
最佳答案
函数是mysqli_query()
不是$mysqli_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')");
关于php - 如何向sql server添加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25217869/