php - 如何向sql server添加数据

标签 php html mysql sql

大家好,我 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/

相关文章:

javascript - 从下拉列表中选择不同类型的值打开不同类型的输入法?

css - 更改屏幕大小时基于图像的链接会重叠(即使调整浏览器窗口的大小)

jquery - 如何创建像这些示例中那样滚动的网站内容?

mysql - 在 Apache Phoenix 中聚合和分组

php - 将 MySQL 表数据回显为 HTML

php - 通过 WordPress Media Uploader 上传图片时出现 HTTP 错误

php - 在 Codeigniter 中抑制特定请求的所有错误

html - 如何将html中的®符号变为斜体?

mysql - 在.bash_profile中已经设置了路径但仍然得到 '-bash: mysql: command not found'

php - openssl_pkey_get_private 返回 false