HTML form to MYSQL DB getting PHP POST error via /r/learnprogramming


HTML form to MYSQL DB getting PHP POST error

So I've been trying to create a simple HTML form that will submit user information to a local MYSQL database. When I try to run it I get "Cannot POST /test/addperson.php". I've tried many other solutions posted around but none of them seem to work.

HTML

<!DOCTYPE html> <html> <body> <h2>User Database</h2> <br> <form action="test/addperson.php" method="post"> <p>First Name: </p> <input type="text" name="first_name"> <p>Last Name: </p> <input type="text" name="last_name"><br> <input type="submit" name="submit"> </form> </body> </html> 

PHP

<?php $connect = mysql_connect("localhost:3306","root", "password"); if(!connect){ die('Connection Failed: ' . mysql_error()); } mysql_select_db("Users", $connect); $user_info = "INSERT INTO employees (first_name, last_name) VALUES ('$_POST[first_name]', '$_POST[last_name]')"; if(!sql_query($user_info, $connect)){ die('Error' . mysql_error()); } echo "Your information was added to the database."; mysql_close($connect); ?> 

Submitted July 12, 2017 at 10:24AM by TheStabCat
via reddit http://ift.tt/2tMHuja

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s