#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Currently Poland, sometimes London, originally Wales . . .
    Posts
    154
    Rep Power
    16

    HTTP Error 400: Bad Request, with basic form


    I am getting a very unexpected HTTP error when posting a form to a PHP script and I was wondering if anyone can suggest why it might be occurring.

    I know this isn't really a PHP question exactly, but I'm not sure where else to turn . . .

    The site I'm working on basically consists of a load of articles stored in a mySQL database.

    I've been working on a method to retrieve a list of articles that match user-inputted search criteria, such as searching on the subject or body of an article.

    I've written a search script and it works fine. When browsing directly to the URL that calls the search script and adding the correct variable names and values into the URL, it will perform a search based on the relevant criteria and return the correct results.

    I then added links for each of the authors, so that clicking the link will retrieve all the articles by a given author. This works too.

    A problem has arisen when posting data through an input form.

    I've removed all the unneccessary bits and bobs from the form and left in only the required fields so that the form looks like:

    Code:
    <form name="searchdata" method="post" action="search.php">
    <center><b><u><font color="#FFFFCC">Search Articles</font></u></b></center><br>
    <input type="text" name="searchvalue" value="Search Here"><br>
    <input type="hidden" name="searchkey" value="allbasic">
    <input type="hidden" name="match" value="like">
    <input type="hidden" name="search" value="1">
    <center><input name="submit" type="submit" value="Search"></center>
    </form>
    Whenever I submit the form, I get an HTTP error 400 that reads:

    "Bad Request
    Your browser sent a request that this server could not understand.
    Client sent malformed Host header"

    This happens with the method as POST or GET.

    This only occurs with the above form. I have one other form on the page and this does not generate the same error or indeed any error at all. It too is quite a simple form, with just a radio button group and a button (a voting widget).

    If I leave out any of the fields in the above form, the form data is posted correctly, no HTTP error occurs and the search script merely tells me that I've left out a required field i.e. the form is posted correctly.

    If I were to take the fields from the form and create a URL of the nature search.php?searchvalue=bob&searchkey=allbasic&match=like&search=1, it will work fine also.

    I have no idea why I am getting an HTTP 400 error when posting the above form, and not only with the above form, but with the above form fields as well - change the field names and it works (but then the search doesn't). I would at least have something to look into if it were happening with other forms, but alas this is not the case.

    It doesn't matter too much if I can't figure it out, as I can always resort to using a bit of JavaScript to create a URL such as the one above and use something like document.location=$theurl to send the data if I have to.

    So, does anyone have any ideas? I'm fully stumped
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Currently Poland, sometimes London, originally Wales . . .
    Posts
    154
    Rep Power
    16
    Ahh - fixed it.

    Short version - the form I mention was setting a header incorrectly with the data as it was 'cos I was doing something silly

    Fixed it now!

IMN logo majestic logo threadwatch logo seochat tools logo