You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HTML表单关联PHP数据库插入脚本失效,请求技术支援

Troubleshooting Your HTML/PHP Form Issue

Let's break down the issues step by step and fix them for you:

1. Root Cause of the "Download PHP Script" Problem

When your browser tries to download the PHP file instead of executing it, this means your web server (like Apache or Nginx) isn't configured to process PHP scripts. Here's how to check:

  • Ensure PHP is installed on your server. Run php -v in the terminal to verify.
  • For Apache: Make sure the mod_php module is enabled, and your virtual host configuration includes AddType application/x-httpd-php .php.
  • For Nginx: Confirm you have the PHP-FPM service running, and your server block has the proper fastcgi_pass directive pointing to PHP-FPM.
  • Also, double-check that your PHP file has a .php extension (not .txt or anything else).

2. Fixes for Your HTML Form

Your HTML has several syntax errors and missing configurations that prevent proper submission:

  • The <form> tag's action attribute is empty – set it to the path of your PHP script (e.g., action="submit_issue.php").
  • Typos: <tittle> should be <title>, maxlenght → maxlength, type"text" → type="text", <img> tag should be closed properly (<img src="logo.png" width="100%" />).
  • Radio button name inconsistency: The first radio group has name="lost call" (with space) and later name="lost_call" – keep the name consistent for proper value submission.
  • Invalid input type: date-time-local should be datetime-local.
  • Broken tags: There's an unclosed <br> tag (<br &lt;br&gt; – fix that to <br>).
  • For multi-line description, use <textarea> instead of a text input for better user experience.

Here's the corrected HTML:

<html>
<head>
    <title>FORMAT FOR TECHNICAL ISSUES</title>
    <link rel="stylesheet" href="/var/www/html/proyecto/css/styles.css">
    <hr>
</head>
<body>
    <div>
        <img src="logo.png" width="100%" />
        <hr>
        <form method="POST" action="submit_issue.php">
            <input type="text" placeholder="NOMBRE" name="Nombre" maxlength="30" size="20" id="nombre">
            <input type="text" name="Extension" placeholder="EXTENSION" maxlength="5" id="extension">
            <br>
            <hr>
            <br><br>
            <h2>CAMPAIGN /CAMPAÑA</h2>
            <br>
            <label for="Campaign">Select your campaign:</label>
            <select name="Campaign" id="campaign">
                <option value="Procall">Procall</option>
                <option value="Tigo">Tigo</option>
                <option value="Spanish">Spanish</option>
            </select>
            <hr>
            <h2>KIND OF FAILURE</h2>
            <label for="incident">Select the type of incident:</label>
            <select id="incident" name="incidente" placeholder="Tipo de incidente">
                <option value="Slow Computer">Slow Computer</option>
                <option value="Headset fail">Headset Fail</option>
                <option value="Zoiper Issue">Zoiper Issue</option>
                <option value="Crm Issue">Crm Issue</option>
                <option value="Spark Issue">Spark Issue</option>
                <option value="Vc Dialer Issue">VC Dialer Issue</option>
                <option value="Network Issue">Network Issue</option>
            </select>
            <textarea id="description" name="Description" placeholder="DESCRIPTION" style="width:300px;height:100px"></textarea>
            <br><br>
            <h2>FAILURE DATE</h2>
            <label for="failure_date">Enter the day and hour when failure occurred:</label>
            <input name="failure_date" type="datetime-local" placeholder="yyyy/mm/dd/hh/mm" id="failure_date" min="2018-05-01T08:30" max="2018-12-30T22:30">
            <br>
            <hr>
            <label for="lost_call">Did you lose any call?:</label>
            <br>
            <input type="radio" name="lost_call" value="yes" id="lost_call_yes"> Yes, I lost a call.
            <br>
            <input type="radio" name="lost_call" value="no" id="lost_call_no"> No, I have not lost any call
            <br><br>
            <label for="document">Did you lose any document or information?:</label>
            <br>
            <input type="radio" name="document" value="yes"> Yes, I lost one or more documents
            <br>
            <input type="radio" name="document" value="no"> No, I have not lost any document.
            <br><br>
            <label for="logout">Did you have to log out?:</label>
            <br>
            <input type="radio" name="logout" value="yes">Yes, I had to logout
            <br>
            <input type="radio" name="logout" value="no">No, I didn't have to logout
            <br><br><br><br>
            <input type="submit" value="Submit Issue">
        </form>
    </div>
</body>
</html>

3. Critical Fixes for Your PHP Script

Your PHP code uses outdated functions and has security vulnerabilities:

  • The mysql_* functions are completely deprecated – use mysqli (improved MySQL extension) instead.
  • Directly inserting $_POST values into SQL causes SQL injection attacks – use prepared statements to prevent this.
  • Table name tec-issues contains a hyphen, so you need to wrap it in backticks (`tec-issues`) in your SQL query.
  • Add a check to ensure the script only runs when the form is submitted (to avoid errors when accessing the PHP file directly).
  • Properly handle missing POST values (you can add validation if needed).

Here's the corrected PHP script (save as submit_issue.php):

<?php
// Only run if form is submitted via POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Use mysqli instead of deprecated mysql_* functions
    $con = mysqli_connect("localhost", "root", "m0l0t0v", "it");

    // Check connection
    if (!$con) {
        die('Could not connect: ' . mysqli_connect_error());
    }

    // Prepare and bind parameters to prevent SQL injection
    $stmt = mysqli_prepare($con, "INSERT INTO `tec-issues` (Nombre, Extension, Campaign, incidente, Description, failure_date, lost_call, document, logout) 
                                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
    mysqli_stmt_bind_param($stmt, "sssssssss", 
        $_POST['Nombre'], 
        $_POST['Extension'], 
        $_POST['Campaign'], 
        $_POST['incidente'], 
        $_POST['Description'], 
        $_POST['failure_date'], 
        $_POST['lost_call'], 
        $_POST['document'], 
        $_POST['logout']
    );

    // Execute the statement
    if (mysqli_stmt_execute($stmt)) {
        echo "1 record added successfully!";
    } else {
        die('Error: ' . mysqli_stmt_error($stmt));
    }

    // Clean up
    mysqli_stmt_close($stmt);
    mysqli_close($con);
} else {
    // Redirect back to form if accessed directly
    header("Location: your_form_page.html");
    exit;
}
?>

Final Checks

  1. Make sure both files are in the same directory on your server, or adjust the action path accordingly.
  2. Verify your MySQL database it exists, and the table tec-issues has all the columns specified in the INSERT query with matching data types.
  3. Ensure the MySQL user root has permission to insert data into the tec-issues table.

内容的提问来源于stack exchange,提问作者average

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:42:46