如何创建用于连接数据库的索引文件

时间:2019-05-29 06:15:48

标签: php html mysql

我正在使用HTML,PHP和MySQL创建表单。我需要尝试将所有3个链接在一起并将数据发送到数据库的帮助。

已经在网上进行了很多研究,我看到我们必须创建某种索引文件,但是由于我是所有这方面的初学者,所以我很难理解该如何进行。我已经使用HTML,PHP和Excel(作为数据库)创建了表单,但是我需要将其转移到MySQL。

<?php

$error = '';
$RequestorName = '';
$SESAID = '';
$Q2C = '';
$Line = '';
$ExpectedDate = '';
$ReasonList = '';
$Description = '';
$checkbox = '';

function clean_text($string)
{
 $string = trim($string);
 $string = stripslashes($string);
 $string = htmlspecialchars($string);
 return $string;
}

if(isset($_POST["submit"]))
{
 if(empty($_POST["RequestorName"]))
 {
  $error .= '<p><label class="text-danger">Please Enter Requestor Name</label> 
  </p>';
 }
 else
 {
  $RequestorName = clean_text($_POST["RequestorName"]);
 }

 if(empty($_POST["SESAID"]))
 {
  $error .= '<p><label class="text-danger">Please Enter SESAID</label></p>';
 }
 else
 {
  $SESAID = clean_text($_POST["SESAID"]);
 }

 if(empty($_POST["Q2C"]))
 {
  $error .= '<p><label class="text-danger">Please Enter Q2C Number</label> 
  </p>';
 }
 else
 {
  $Q2C = clean_text($_POST["Q2C"]);
 }

 if(empty($_POST["Line"]))
 {
  $error .= '<p><label class="text-danger">Please Enter Line Number</label> 
  </p>';
 }
 else
 {
  $Line = clean_text($_POST["Line"]);
 }

 if(empty($_POST["ExpectedDate"]))
 {
  $error .= '<p><label class="text-danger">Expected Date is required</label> 
  </p>';
 }
 else
 {
  $ExpectedDate = clean_text($_POST["ExpectedDate"]);
 }

 if(!isset($_POST["ReasonList"]))
 {
  $error .= '<p><label class="text-danger">Please select a reason</label> 
  </p>';
 }
 else
 {
  $ReasonList = clean_text($_POST["ReasonList"]);
 }

 if(empty($_POST["Description"]))
 {
  $error .= '<p><label class="text-danger">Description is required</label> 
  </p>';
 }
 else
 {
  $Description = clean_text($_POST["Description"]);
 }

 if(!isset($_POST["checkbox"]))
 {
  $error .= '<p><label class="text-danger">Please upload all the files</label> 
  </p>';
 }

 if($error == '')
 {
  $file_open = fopen("Revision_Tracker.csv", "a");
  $no_rows = count(file("Revision_tracker.csv"));
  if($no_rows > 1)
  {
   $no_rows = ($no_rows - 1) + 1;
  }
  $form_data = array(
   'sr_no'  => $no_rows,
   'RequestorName' => $RequestorName,
   'SESAID' => $SESAID,
   'Q2C'  => $Q2C,
   'Line'  => $Line,
   'ExpectedDate' => $ExpectedDate,
   'ReasonList'  => $ReasonList,  
   'Description' => $Description
  );
  fputcsv($file_open, $form_data);
  $error = '<label class="text-success">Thank you!</label>';
  $RequestorName = '';
  $SESAID = '';
  $Q2C = '';
  $Line = '';
  $ExpectedDate = '';
  $ReasonList = '';
  $Description = '';
}
}
<input type="text" name="RequestorName" placeholder="Enter Name" class="form-control" value="<?php echo $RequestorName; ?>" />
     </div>
      <div class="form-group">
      <label>SESA ID of Requestor</label>
      <input type="text" name="SESAID" placeholder="Enter SESA ID" class="form-control" value="<?php echo $SESAID; ?>" 
      </div>


On clicking Submit the values entered on the form will move to Excel. This operation works for me. I want to know how to implement it with MySQL. Everything I read is just going over my head.

0 个答案:

没有答案