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

crawl.php无法向数据库写入数据,WAMP64及线上服务器故障求助

Troubleshooting Guide: Database Not Receiving Data from crawl.php

Let’s walk through the potential issues step by step—starting with the frontend code you shared, then moving to backend and database checks.

Frontend Code Fixes (Immediate Issues)

Looking at your HTML and JavaScript, there are a few syntax/logic errors that could break the workflow entirely:

  1. Incorrect Alert Selector
    You’re using $("textGradient") to target the status alert, but this is a class selector—you need to add a dot (.) before the class name:

    // Wrong
    $("textGradient").text("Processing Please wait...");
    // Correct
    $(".textGradient").text("Processing Please wait...");
    

    This is why you’re stuck on the "Processing" message—your code can’t actually find or update the alert element.

  2. Broken Button Re-enable Logic
    In the AJAX success callback, you’re using .text() instead of .prop() to re-enable the button, and the syntax is incorrect. Fix it to:

    $("#buttonSubmit").prop('disabled', false).text('Submit');
    

    This will re-enable the button and reset its text after a successful request.

  3. Duplicate name Attribute
    Your URL input has two name="url" attributes. Remove one to avoid potential parsing conflicts:

    <input type="url" class="form-control" name="url" placeholder="Submit URL here..." required aria-label="Search" aria-describedby="basic-addon1" />
    
  4. Missing AJAX Error Handling
    Right now, you have no way to know if the request fails. Add an error callback to debug issues:

    $.ajax({
        type: 'post',
        url: 'crawl.php',
        data: $('form').serialize(),
        success: function() {
            $("#buttonSubmit").prop('disabled', false).text('Submit');
            $(".textGradient").html("The system has received the url");
        },
        error: function(xhr, status, error) {
            $("#buttonSubmit").prop('disabled', false).text('Submit');
            $(".textGradient").html(`Error: ${error} (Status: ${status})`);
            console.log(xhr.responseText); // Log full server response to console
        }
    });
    

    This will show you exactly if the request fails and what the server returns.

Backend (crawl.php) & Database Checks

Even with a fixed frontend, if crawl.php isn’t working correctly, the database won’t update. Here’s what to verify:

  • Confirm POST Data Reception
    At the top of crawl.php, add code to check if it’s receiving the URL:

    <?php
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        if (!isset($_POST['url'])) {
            die("Error: URL parameter missing");
        }
        $url = $_POST['url'];
        // Log or print the URL for testing (remove in production)
        error_log("Received URL: " . $url);
        echo "Received URL: " . $url;
    }
    

    Submit the form again—if you don’t see this response, the data isn’t reaching the script.

  • Validate Database Connection
    Ensure your credentials are correct (local WAMP and online servers often use different usernames/passwords). Add error handling to your connection code:

    // Example with mysqli
    $conn = mysqli_connect('localhost', 'username', 'password', 'database_name');
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    

    This will tell you immediately if the database connection fails.

  • Check SQL Insert Logic
    Make sure your INSERT query is valid and includes error handling. Use prepared statements to avoid SQL injection:

    $sql = "INSERT INTO your_table_name (url_column) VALUES (?)";
    $stmt = mysqli_prepare($conn, $sql);
    mysqli_stmt_bind_param($stmt, "s", $url);
    
    if (mysqli_stmt_execute($stmt)) {
        echo "URL added successfully";
    } else {
        die("Insert failed: " . mysqli_error($conn));
    }
    
  • Server Permissions (Online Server)

    • Ensure crawl.php has correct file permissions (usually 644).
    • Verify your database user has INSERT permissions for the target table.

Debugging Steps to Follow

  1. Open your browser’s Developer Tools (F12), go to the Network tab, then submit the form. Check if the request to crawl.php is sent, and view the Response tab to see what the server returns.
  2. Test crawl.php directly with Postman or curl: send a POST request with url=https://example.com and check if the database updates.
  3. Review server error logs (WAMP: wamp64/logs/php_error.log; online server: check your hosting control panel) for PHP or database errors.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 16:17:43