如何删除 Jquery PHP 回显错误?

How to remove Jquery PHP echo error?

我有一个 Web 表单代码,其中有两个字段名称、日期和标题。我在我的代码中使用 jquery 来显示当前日期和日历,当我在日期字段中更改日期时,它会自动在标题字段中更改。我在标题字段中有一些硬代码。现在我的问题是,当我更改日期时,硬代码不会显示,我的 php 代码是另一个文件,无法获取标题的值,也无法在数据库 mysql 中存储任何值。

这是我的代码。

d2.php

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" type="text/css" href="style.css">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
    <script>
$(document).ready(function() {
    $("#mydate").datepicker({
    dateFormat: "dd-M-y",
    onSelect: function(dateText, inst) {
            $("#dt_title").html(dateText);
        }
    }).datepicker("setDate", new Date());
});   
</script>
  </head>
<body>

 <form action="pd1.php" method="POST" enctype="multipart/form-data">

   <table width="547" class="tblbdr" >
    <tr>
        <td height="23"  colspan="6" class="head"><p>  Morning Breifing</p></td>
</tr>
 <tr> <td height="10"></td></tr>
<tr><td class="celltext"><b>Date:</b> </td> <td><input name="mydate" type="text" id="mydate" style="width:200px"> </td></tr>
<tr>

<tr><td class="celltext"><b>Title: </b><br> </td> 

<td class="celltext" style="width:200px" ><span id="dt_title"> <input name="title" type="text"  value=" MB | Falcons | 
<?php  echo date("d-M-y");?>" style="width:200px"/> </span></b> </td> </tr>
</tr>
<td class="celltext"><b>Upload File:</b></td>
    <td colspan="4" bordercolorlight="#006666">  
    <input type="file" name="myfile" id="myfile" width="100%" size=80/>
    </td></tr>
    <td><input type="submit" value="Save"/> </td> <td> </td>
    <td width="151">

   </td>
    <tr>
    <td height="12">
    </td>
    <td width="290">

   </td> </tr>
   </table>
</form>
</body>
</html>

这是我的 php 代码

pd1.php

<?php
$sector_fi_id = $_POST['sub_sector_fi_id'];
$client_fi_id =$_POST['client_fi_id'];
$significance='PIT';
//$significance=$_POST['significance'];
$sector_corp_id = $_POST['sub_sector_corp_id'];
$client_corp_id = $_POST['client_corp_id'];

$eco_sector_id = $_POST['eco_sector_id'];
$life_pacra_id='People';
//$life_pacra_id = $_POST['life_pacra_id'];
if($sector_fi_id!=0)
    $main_sector_id = $sector_fi_id;
else    
    $main_sector_id = $client_corp_id;

$regulator_id = $_POST['regulator_id'];
$research_source_id = $_POST['research_source_id'];
$magazine_id = $_POST['magazine_id'];
$newspaper_id = $_POST['newspaper_id'];
$rating_source_id = $_POST['rating_source_id'];
$Filepath=  "";
$summary='';
$weblink = $_POST['weblink'];

$Date = isset($_REQUEST['mydate']) ? $_REQUEST['mydate'] : "";
$Date=date('Y-m-d h:i:s',strtotime($Date));
$title=$_POST['title'];
//$uploaddir = '../upload/';
$uploaddir = "../../../pages/upload/";
$uploadfile = $uploaddir . basename($_FILES['myfile']['name']);

if ($_FILES["myfile"]["name"]!="")
    {   
            //$Filepath=  "upload/" . str_replace('-','_',$_FILES["myfile"]["name"]);
        $Filepath=  "upload/" .($_FILES["myfile"]["name"]);
        if (move_uploaded_file($_FILES['myfile']['tmp_name'], $uploadfile)) {
            echo "File is valid, and was successfully uploaded.\n";
        }
        else {
        echo "Upload failed";
        }

    }
    echo $Filepath;
////creating connection//////
$db="test123";
$con = mysql_connect('localhost', 'root' , '');
if (! $con)
die(mysql_error());
mysql_select_db($db , $con) or die("Select Error: ".mysql_error());

$result=mysql_query("INSERT INTO mainentry(Entrydate,  Filepath, Recordtitle,  Summary,significance,record_time,Subsectorid,weblink) VALUES ('$Date', '$Filepath', '$title', '$content','$significance',now(),'$main_sector_id','$weblink')") or die("Insert Error: ".mysql_error());

$main_entry_id = mysql_insert_id();

$result = mysql_query ("INSERT INTO main_entry_group(main_entry_record_id,fi_sector_id,fi_client_id,corp_sector_id,corp_client_id,economy_id,life_pacra_id,source_newpaper_id,source_mag_id,source_research_id,source_regulator_id,source_rating_id) VALUES ('$main_entry_id','$sector_fi_id','$client_fi_id','$sector_corp_id','$client_corp_id','$eco_sector_id','$life_pacra_id','$newspaper_id','$magazine_id','$research_source_id','$regulator_id','$rating_source_id' )");
header("Location: pd_new.php? info=Record saved Successfully");

 exit;

 ?>

日期不变的输出

日期更改后的输出

通过 $("#dt_title").html(dateText); 你删除了跨度内的输入字段,只写纯日期文本。您应该设置标题输入的值而不是跨度 html。固定码:

onSelect: function(dateText, inst) {
            $("#dt_title input[type='text']").val(dateText);
        }

要在输入中保留标题并仅更改日期,您需要在输入的附加属性中保存标题:

<input name="title" type="text" value=" MB | Falcons | <?php echo date("d-M-y");?>" data-title="MB | Falcons | " style="width:200px"/>

然后在 jQuery 中通过添加属性中的标题更改输入值:

$("#dt_title input[type='text']").val($("#dt_title input[type='text']").attr('data-title')+dateText);