-4

If I make insert_teacher('bla bla','bla bla','dqsd') in PHP file, but when I want to make it with HTML form it doesn't show me anything, and nothing is inserted in my DB.

<?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>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Stevlulz
  • 11
  • 1

2 Answers2

1

There's a lot wrong here but I'll try help anyway.

First your submit should have a name. Eg

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

Second, you call the filled form with the submit button's name. Eg

if(isset($_POST['insertx'])){

//your code

}

Third, read on how insert in php in PDO or mysqli unless you want to get hacked! (NB:mysqli_real_escape_string)

There's a lot to learn, but its not rock hard. All the best

chris85
  • 23,846
  • 7
  • 34
  • 51
Khan Luke
  • 168
  • 1
  • 13
0

you have to add name to the submit tag:

<input type="submit" name="submit">
JochenJung
  • 7,183
  • 12
  • 64
  • 113