PHP帮助初学者

I am very green to php and I am trying to create code that will allow me to enter information to a database I constructed. Everytime I run it though I get an object not found error 404. I have searched google and have found some information however I am unable to correct my error, Any help would be greatly appreciated. I do not know what is going on I think the problem is in the HTML part because when I run the php code it works. something with the submit button and connecting to the php code I think but again I am very new to this any help would be greatly appreciated.

John, Here is the code

<html>
<head>
</head>
<body>
<form action = 'insertform.php' method='post'>
Maker:<input type="text" name="maker"><br /><br />
Contact:<input type="text" name="contact"><br /><br />
Location:<input type="text" name="location"><br /><br />
Phone:<input type="int" name="phone"><br /><br />
<input type="submit" name="submit">
</form>
</body>
</html>



<?php
if (isset($_POST['submit'])){
    $con = mysql_connect("localhost","root","");
    if(!$con) {
        die("Cannot Connect: " . mysql_error());
    }
    mysql_select_db("ListParts2",$con);

    $sql = "INSERT INTO Manufacturer (Maker,Contact,Location,Phone) VALUES    ('$_POST[maker]','$_POST[contact]','$_POST[location]','$_POST[phone]')";

    mysql_query($sql,$con);
    mysql_close($con);
}
?>

Just leave the action blank and the form will post to the same page which is what i think you are trying to do..

<form action='' method='post'>

A 404 error indicates that the webserver was unable to find the requested file. So the question is whether your webserver is configured correctly, and the URL that you use is correct.

The problem is not the contents of your file, as you have pasted in your question.

Is your php file indeed called insertform.php ?

The HTML form attribute "action" requires the correct path to the file. If the file is referencing itself however, you can leave it blank and it will simply post to itself.

So make sure it's definitely trying to post to the correct directory and file.

Another thing you may need to add to get the form working is the form elements enctype attribute.

It has various options, the one you would want to use for that form is "multipart/form-data", so:

<form action="" method="POST" enctype="multipart/form-data">