PHP表单提交不工作


php form submission not working

我用同样的方法制作了多个页面,但由于某种原因,无论我怎么尝试,我都无法将某些字段转移到电子邮件字段中。我完全没有得到任何数据。这是HTML

表单
    <form action="interest.php" method="post" >                                                   <!-- BEGIN cardetail Form -->
    <table>
    <tr>
    <td width="50" class="alignRight" style="font-weight:bold;" >Year:</td>
    <td width="10px"></td>
    <td width="112"><p name="carYear">2011</p></td>
    <td class="alignRight" style="font-weight:bold;" >Color:</td>
    <td width="10px"></td>
    <td><p name="carColor">Red</p></td>
    </tr>
    <tr>
    <td class="alignRight" style="font-weight:bold;" >Make:</td>
    <td width="10px"></td>
    <td ><p name="carMake">Honda</p></td>
    <td width="50" class="alignRight" style="font-weight:bold;">Trim:</td>
    <td width="10px"></td>
    <td>Car has some sort of trim on it.</td>
    </tr>
    <tr>
    <td class="alignRight" style="font-weight:bold;" >Model:</td>
    <td width="10px"></td>
    <td><p name="carModel">Accord</p></td>
    <td class="alignRight" style="font-weight:bold;">Miles:</td>
    <td width="10px"></td>
    <td><p>180,000</p></td>
    </tr>
    <tr>
    </tr>
    <tr>
    <td class="alignRight" style="font-weight:bold;">Options:</td>
    <td width="10px"></td>
    <td colspan="4">
    <p>
        Power Windows, 
            Power Locks, 
            Keyless Entry, 
            Cruise Control, 
            Climate Control, 
            2.6L V-Tech
    </p>
    </td>
    </tr>
    <tr>
    <td style="font-weight:bold;">Repairs/Maintenance:</td>
    <td width="10px"></td>
    <td colspan="4">Fuel line flush, Transmission flush, Coolant flush, Oil Change, New Oil Filter, New Fuel Filter, New Air Filter, New Radiator, Painted Driverside Door, New Tires, Brand New Wax Job, and Fully Detailed.</td>
    </tr>
    <tr>
<td class="alignRight"></td>
        <td></td>
<td><a href="#top">Back to Top</a></td>
        <td class="alignRight" style="font-weight:bold;">Price:</td>
        <td></td>
        <td class="price"><p><span class="price"><?php echo $carPrice; ?>$6,000</span><input class="showInterest" type="submit" name="showInterest" id="showInterest" value="Show Interest" /></td>
    </tr>
    </table>
    </form>                     <!-- END cardetail Form -->

这是php代码,我试图得到的信息转移到。

    <?php echo $_POST['carYear'] . " / " . $_POST['carMake'] . " / " . $_POST['carModel'] . " / " . $_POST['carColor']; ?>

现在,当我从服务器上运行代码时,我得到的是3 "/"。由于某种原因,$_POST没有抓取任何数据。我试过把它传递到一个变量,只是插入的数据,因为它是在例子中。我做错了什么?我是不是漏掉了一个小错别字?

为什么你没有得到任何东西是因为,你没有发布任何东西!

你只有一个<input>,它是这个:

  <input class="showInterest" type="submit" name="showInterest"
               id="showInterest"  value="Show Interest" />

并且,这只是一个submit按钮,它本身不做任何事情。它只能提交在另一个<input type=''>标签内的内容。例如:如果你有

<input type='text' name='carYear' />您可以通过以下命令检索该值echo $_POST['carYear']; .

我没看到任何东西。你不能发布纯文本,无论它是否在你的<form></form>标签内。你必须创建输入

好,把这些值脚本放到HTML文件中,

  <input type='text' name='carYear' value='' />
  <input type='text' name='carMake' value='' />
  <input type='text' name='carModel' value='' />
  <input type='text' name='carColor' value='' />

用汽车详细信息填充所有value='',并提交表单

表单中除了提交按钮没有任何输入,这就是为什么在

中没有任何数据的原因
    <?php echo $_POST['carYear'] . " / " . $_POST['carMake'] . " / " . $_POST['carModel'] . " / " . $_POST['carColor']; ?>

要有一个值,比如说在$_POST['carYear']中你应该在表单的某个地方添加

<input type="text" name="carYear">

在这里了解更多关于php表单的信息

您没有发布任何内容。但是,如果你想保持你的结构,并真正发布一些东西。添加一些隐藏的输入,其中包含您想要发布的值。

您的输入将像这样:

<input type="hidden" name="carYear" value="2011"/>
<input type="hidden" name="carMake" value="Honda"/>
<input type="hidden" name="carModel" value="Accord"/>
<input type="hidden" name="carColor" value="Red"/>