PHP联系/订单表单故障求助(switch语句相关)
Hey there, I feel your frustration—spending a week troubleshooting something when you’re not familiar with PHP must be so draining, especially since you’re doing this for your dad’s site. Let’s break this down step by step to figure out why the order content isn’t coming through, even though contact details work perfectly.
Key Troubleshooting Steps
Double-check form field names
Make sure every input field for order details has a matchingnameattribute in your HTML form. For example, if your PHP code is supposed to graborder_item, your input should look like:<input type="text" name="order_item" placeholder="Your order item">If the
namevalues don’t match what the PHP script expects, the data will never be captured.Debug to see what data is actually being sent
Even if you don’t know PHP, you can add a simple line to see all form data. At the very top of the PHP script that handles form submissions, add:var_dump($_POST);When you submit the form, this will print out every piece of data sent. If you don’t see your order fields here, the problem is with the form itself. If you do see them, the issue is in how the data is being included in the email or stored.
Compare contact vs order data handling
Find the section of the original code that processes and sends contact info (like name, email). Then compare that to where you added order content. Chances are you missed adding the order variables to the email body, or there’s a typo in the variable name. For example:
If contact info uses:$email_body = "Name: " . $_POST['name'] . "\nEmail: " . $_POST['email'];Make sure you’re adding order data like this:
$email_body .= "\nOrder Details: " . $_POST['order_details'];(The
.=appends the order info to the existing email body.)Check dynamic/hidden order fields
If order details are generated dynamically (like from a shopping cart) or stored in hidden fields, right-click the form on your site and select "Inspect" to verify those fields have the correct values filled in before submission. Empty or incorrect values here mean nothing will be sent to PHP.
Take it slow—since you already got the contact part working, you’re halfway there! Even small checks can help pinpoint the issue. And don’t beat yourself up about not knowing PHP—we all start somewhere.
内容的提问来源于stack exchange,提问作者Neniariel

