HTML表单不适用于PHP代码

时间:2016-08-18 00:10:15

标签: javascript php jquery html css

如果我在PHP文件中创建insert_teacher('bla bla','bla bla','dqsd'),但是当我想用HTML表单创建它时,它不显示任何内容,并且我的数据库中没有插入任何内容。

<?php
  include_once("resources/functions.php");
echo 1;
  if(isset($_POST['submit']))
  {
      $name=$_POST['name'];
      $exp=$_POST['exp'];
      $sub=$_POST['sub'];

         $insert=insert_teacher($name,$exp,'dqsd');// return 1 or 0
          echo $insert;



  }

?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
 <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>

<header>
  <h1>City Gallery</h1>
</header>

<ul class="sidenav">
  <li><a  href="index.php">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a class="active" href="setup_teachers.php">Teachers Section</a></li>
</ul>

<div class="content">
<h3 class="warning"><?php if(isset($b)) echo $b; ?></h3> 
<h3>Adding teachers information</h3>

<div>
  <form action="" method="POST" >
    <label for="fname">FullName</label>
    <input type="text" id="fname" name="name">

    <label for="lname">Experience</label>
    <input type="text" id="lname" name="exp">

    <label for="subject">Subject</label>
    <select id="country" name="sub">
      <option value="physics">physique</option>
      <option value="maths">mathematique</option>
      <option value="english">Anglais</option>
    </select>
    <input type="submit">
  </form>
</div>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

这里有很多错误,但无论如何我都会尝试帮助。

首先,您的提交应该有一个名称。例如

# Get data
import urllib.request as request
request.urlretrieve('http://seanlahman.com/files/database/baseballdatabank-master_2016-03-02.zip', "baseballdatabank-master_2016-03-02.zip")
from zipfile import ZipFile
zip = ZipFile('baseballdatabank-master_2016-03-02.zip')
zip.extractall()

import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

batting_df = pd.read_csv("baseballdatabank-master\core\Batting.csv")
batting_df = batting_df[batting_df['AB'] > 20]
batting_df['batting_average'] = batting_df['H'] / batting_df['AB']

# Plot distribution
batting_averages = batting_df['batting_average'].dropna()
batting_averages.plot.kde()

# Plot confidence interval
import scipy.stats
import numpy as np, scipy.stats as st
stderr = st.sem(batting_averages)
interval1 = (batting_averages.mean() - stderr * 1.96, batting_averages.mean() + stderr * 1.96)
plt.plot(interval1[0], 12)
plt.show()

其次,使用提交按钮的名称调用填充的表单。例如

<input type="submit" name="insertx"/>

第三,阅读如何在if(isset($_POST['insertx'])){ //your code } PDO中插入php,除非你想被黑客攻击! (NB:mysqli

有很多东西需要学习,但它不是很难。 一切顺利

答案 1 :(得分:0)

您必须为提交标记添加名称:

<input type="submit" name="submit">