user3717206 user3717206 -4 years ago 59
HTML Question

Connecting PHP Code and Submit Form to mySQL Database

Hi 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 into the database. My problem is that the code is connecting but the html isn't posting the variables to the PHP file. I could really use some help. thanks

This is my Html 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 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