当我尝试使用内联php访问cookie时,无论出于何种原因,我的提交都会消失。
<div id='add_form'>
<form id='form' method='post' action='reg.do.php'>
<label for='date'>Date of Charge:</label><input type='text' name='date' id='date' maxlength='10' value='<?php echo (isset($_POST['name']) ? sanitize($_POST['name']) : ''); ?>' ><br>
<label for='vendor'>Vendor:</label><input type='text' name='vendor' id='vendor' value='<?php echo (isset($_POST['vendor']) ? sanitize($_POST['vendor']) : ''); ?>' ><br>
<label for='amount'>Amount:</label><input type='text' name='amount' id='amount' value='<?php echo (isset($_POST['amount']) ? sanitize($_POST['amount']) : ''); ?>' ><br>
<label for='service'>Description of Service:</label><input type='text' name='service' id='service' value='<?php echo (isset($_POST['service']) ? sanitize($_POST['service']) : ''); ?>' ><br>
<label for='winner'>Winner:</label><input type='text' name='winner' id='winner' value='<?php echo (isset($_POST['winner']) ? sanitize($_POST['winner']) : ''); ?>' ><br>
<label for='job'>Job Number:</label><input type='text' name='job' id='job' value='<?php echo (isset($_POST['job']) ? sanitize($_POST['job']) : ''); ?>' ><br>
<input type='hidden' name='user' id='user' value='<?php echo (isset($_COOKIE['cookie_id']) ? sanitize($_COOKIE['cookie_id']) : ''); ?>' >
<input type='submit' value='Submit'>
</form>
</div>
如果我删除了最后一个隐藏的输入字段或将$_COOKIE
内部的$_POST
访问权限更改为{{1}},则会显示提交按钮。我该如何解决这个问题?
答案 0 :(得分:1)
请参阅http://php.net/manual/ro/reserved.variables.cookies.php,我认为您需要在Cookie上使用htmlspecialchars函数。
答案 1 :(得分:0)
你启用了display_errors吗?也许你的代码中有一个错误,所以你的内联IF条件中的php断开,就像一个未闭合的); - )
试试这个......
<div id='add_form'>
<form id='form' method='post' action='reg.do.php'>
<label for='date'>Date of Charge:</label><input type='text' name='date' id='date' maxlength='10' value='<?php echo (isset($_POST['name']) ? sanitize($_POST['name']) : ''); ?>' ><br>
<label for='vendor'>Vendor:</label><input type='text' name='vendor' id='vendor' value='<?php echo (isset($_POST['vendor']) ? sanitize($_POST['vendor']) : ''); ?>' ><br>
<label for='amount'>Amount:</label><input type='text' name='amount' id='amount' value='<?php echo (isset($_POST['amount']) ? sanitize($_POST['amount']) : ''); ?>' ><br>
<label for='service'>Description of Service:</label><input type='text' name='service' id='service' value='<?php echo (isset($_POST['service']) ? sanitize($_POST['service']) : ''); ?>' ><br>
<label for='winner'>Winner:</label><input type='text' name='winner' id='winner' value='<?php echo (isset($_POST['winner']) ? sanitize($_POST['winner']) : ''); ?>' ><br>
<label for='job'>Job Number:</label><input type='text' name='job' id='job' value='<?php echo (isset($_POST['job']) ? sanitize($_POST['job']) : ''); ?>' ><br>
<input type='hidden' name='user' id='user' value='<?php echo ( isset($_COOKIE['cookie_id']) ) ? sanitize($_COOKIE['cookie_id']) : ''; ?>' >
<input type='submit' value='Submit'>
</form>
</div>
顺便说一下......最好使用某种模板引擎而不是内联php代码。