HTML input value, PHP not recognized

时间:2015-09-01 21:45:02

标签: php html include

I have a project (index.php) that is essentially a HTML webpage. I am trying to use an 'include' function to bring in the header and footer (header.php, footer.php). I'm also trying to have the current date automatically load in a textbox. While I believe the syntax for all of these are correct, no actual PHP statements seem to execute or get recognized. I discovered this by adding a simple echo statement to the page.

Can anyone give me advice? I'm at a loss.

HTML Input Value for date:

<p><label>Order Date:</label> <input value="<?php echo date('m/d/Y'); ?>" maxlength="20" size="10" name="txtOrderDate" type="text" pattern="\d{1,2}/\d{2}/\d{4}" required/></p>

Statements used for header/footer (difference obviously being file name, referenced first and last line of index.php):

<?php include '../view/header.php'; ?>`

Header.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- header -->
<head>
    <title>Order Form</title>
        <link rel="stylesheet" type="text/css" href="../view/main.css" />
    </title>
</head>

Footer.php:

<div id="footer">
    <p>
        &copy; <?php echo date("Y"); ?> Ordering Form
    </p>
</div>
</body>

Index.php (the beginning/end got broken up a bit, but I think everything is there)

<!-- include header --> 
<?php require_once '../view/header.php'; ?>
 <?php $today = date("m/d/Y"); ?>
<body>
<h1> Order Form </h1>
    <div id="wrapper">
    <form method="post" action="../model/A03_OrderForm.php">
    <fieldset>
<!-- body -->
<body>
    <div id="wrapper">
    <form method="post" action="../model/A03_OrderForm.php">
    <fieldset>

    <div class="container">
    <p><label>Order Date:</label> <input value="<?php echo $today; ?>" maxlength="20" size="10" name="txtOrderDate" type="date" pattern="\d{1,2}/\d{2}/\d{4}" required/></p>
    </div></br>

    <div class="container">
    <p><label>Salutation:</label> <select name="selSalutation"> <option selected="selected" value="">(none)</option><option value="Mr">Mr.</option><option value="Mrs">Mrs.</option><option value="Ms">Ms.</option><option value="Miss">Miss</option><option value="Dr">Dr.</option></select></p>
    <p><label>First Name:</label> <input maxlength="20" name="txtFirstName" type="text"  pattern="[A-Za-z]+" required/></p>
    <p><label>Middle Initial:</label> <input maxlength="1" size="2" name="txtMiddleInit" pattern="[A-Za-z]" "type="text" /></p>
    <p><label>Last Name:</label> <input maxlength="20" name="txtLastName" type="text" pattern="[A-Za-z]+" required/></p>
    <p><label>Suffix:</label> <select name="selSuffix"> <option selected="selected" value="">(none)</option><option value="Jr">Jr</option><option value="Sr">Sr</option><option value="I">I</option><option value="II">II</option><option value="III">III</option><option value="IV">IV</option><option value="V">V</option></select></p>
    </div></br>

    <div class="container">
    <p><label>Address:</label> <input maxlength="30" size="36" name="txtAddress" type="text" required/></p>
    <p><label>City:</label> <input maxlength="20" name="txtCity" type="text" pattern="[A-Za-z0-9\s]+" required/></p>
    <p><label>State:</label> <select name="selState"> <option selected="selected" value="DEFAULT">(none)</option> <option value="AL">AL</option> <option value="AK">AK</option> <option value="AZ">AZ</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="CT">CT</option> <option value="DE">DE</option> <option value="DC">DC</option> <option value="FL">FL</option> <option value="GA">GA</option> <option value="GU">GU</option> <option value="HI">HI</option> <option value="ID">ID</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="IA">IA</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="ME">ME</option> <option value="MD">MD</option> <option value="MA">MA</option> <option value="MI">MI</option> <option value="MN">MN</option> <option value="MS">MS</option> <option value="MO">MO</option> <option value="MT">MT</option> <option value="NE">NE</option> <option value="NV">NV</option> <option value="NH">NH</option> <option value="NJ">NJ</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="NC">NC</option> <option value="ND">ND</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OR">OR</option> <option value="PA">PA</option> <option value="RI">RI</option> <option value="SC">SC</option> <option value="SD">SD</option> <option value="TN">TN</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="VT">VT</option> <option value="VA">VA</option> <option value="WA">WA</option> <option value="WV">WV</option> <option value="WI">WI</option> <option value="WY">WY</option></select></p>
    <p><label>Postal Code:</label> <input maxlength="10" size="14" name="txtPostalCode" type="text" pattern="[0-9]{5}" required/></p>
    </div></br>

    <div class="container">
    <p><label>Item No:</label> <input value="01" maxlength="30" name="txtItem" type="number" required/></p>
    <p><label>Quantity:</label> <input value="0" maxlength="20" size="14" name="txtQuantity" type="number" required/></p>
    <p><label>Price:</label> <input value="0.00" maxlength="50" size="14" name="txtPrice" type="number" step="0.01" required/></p>
    </div></br>

    <div class="submit"><input class="button" value="Submit" type="submit" name="btnSubmit" /> <input class="button" value="Reset" type="reset" name="btnReset" />
    <div></div>
    </div>
    </form>
    </fieldset></div>
 <!-- include footer -->
<?php require_once '../view/footer.php'; ?>

As a reminder, none of the PHP statements execute on screen.


Thanks for the input thus far.

One thing to add is the webpage loads and operates just fine except the header/footer are not included (therefore no CSS either) and the date does not load in the textbox. Beyond those two things, it's golden.

ANSWERS TO COMMENTS:

  • Using XAMPP and Notepad++
  • Local
  • Not sure what is meant by the verbatim comment. When I view the source code from the page it is exactly as written in my text editor?

2 个答案:

答案 0 :(得分:0)

<?php $today = date("m.d.y"); ?>

<p><label>Order Date:</label> <input value="<?php echo $today; ?>" name="txtOrderDate" type="date"></p> 

try like this

2nd

make new php file (time.php) copy code from here to it run it on your pc

    <?php

$today = date("m.d.y");                         // 03.10.01
echo = $today;
?>

is that work?

I think that beater solution is to use date picker for this u will not have problem in future how user use date m.d.y m/d/y and so on.

and if possible can u share all code?

答案 1 :(得分:0)

解决!我从'index.php'复制了文本,删除了文件,并将其粘贴到新工作表上。文本框值加载今天的日期,页眉/页脚已成功显示。

谢谢大家的回复和想法。非常感谢!