user3717206 user3717206 -4 years ago 66
HTML Question

Connecting PHP source code and submit form to MySQL Database

I'm trying to learn PHP and I'm trying to connect a MySQL database with my PHP code to make a submit form that lets me input data into the database. My problem is that the source code is connecting but the HTML isn't posting the variables to the PHP file. I could really use some help.

This is my HTML source code

<html>

<head>
<title>Form Input Data</title>
</head>

<body>

<table border="1">
<tr>
<td align="center">Form Input Employees Data</td>
</tr>
<tr>
<td>
<table>
<form action="input.php" method="POST">
<tr>
<td>Name</td>
<td><input type="text" name="name" size="20">
</td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" size="40">
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit"
name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>





And this is my PHP source code

<?php

$user_name = "fees0_14446440";
$password = "********";
$database = "fees0_14446440_addressbook";
$server = "sql107.0fees.net";

mysql_connect("$server","$user_name","$password");

mysql_select_db("$database");


$order = "INSERT INTO Trial

(name, address)

VALUES

('$name',

'$address')";


$result = mysql_query($order);

if($result){

echo("<br>Input data is succeed");

} else{

echo("<br>Input data is fail");

}
?>

Answer Source

You can find the POST data in PHP's $_POST variable. It should hold all the values that were passed via the POST method.

$name = $_POST["name"];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download