如何删除 Jquery PHP 回显错误? [关闭]
Posted
技术标签:
【中文标题】如何删除 Jquery PHP 回显错误? [关闭]【英文标题】:How to remove Jquery PHP echo error? [closed] 【发布时间】:2015-09-12 22:38:29 【问题描述】:我有一个网络表单代码,其中有两个字段名称,日期和标题。我在我的代码中使用 jquery 来显示带有日历的当前日期,当我在 Date 字段中更改日期时,它会在 Title 字段中自动更改。我在标题字段中有一些硬代码。现在我的问题是,当我更改日期时,硬代码不显示,而我的另一个文件的 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 class="tblbdr" >
<tr>
<td colspan="6" class="head"><p> Morning Breifing</p></td>
</tr>
<tr> <td ></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" size=80/>
</td></tr>
<td><input type="submit" value="Save"/> </td> <td> </td>
<td >
</td>
<tr>
<td >
</td>
<td >
</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;
?>
日期不变的输出
日期更改后的输出
【问题讨论】:
【参考方案1】:$("#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);
【讨论】:
那我如何在我的输入字段中使用它? 你应该使用$("#dt_title input[type='text']").val(dateText);
而不是$("#dt_title").html(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);
以上是关于如何删除 Jquery PHP 回显错误? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章