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
Try the following:
<?php
$user_name = "fees0_14446440";
$password = "********";
$database = "fees0_14446440_addressbook";
$server = "sql107.0fees.net";
mysql_connect("$server","$user_name","$password");
mysql_select_db("$database");
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$address = $_POST['address'];
$order = mysql_query("INSERT INTO Trial (name, address) VALUES ('$name', '$address')");
if ($order) {
echo '<br>Input data is successful';
} else {
echo '<br>Input data is not valid';
}
}
?>
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"];
put POST values into variable
$name=$_POST['name'];
$address=$_POST['address'];
before sql query and write sql query as
$order = "INSERT INTO Trial
(name, address)
VALUES
('".$name."',
'".$address."')";
Try this
<html>
<head>
<title>Form Input Data</title>
</head>
<body>
<form action="input.php" method="POST">
<table border="1">
<tr>
<td align="center">Form Input Employees Data</td>
</tr>
<tr>
<td>
<table>
<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>
</form>
In PHP code
$order = "INSERT INTO Trial
(name, address)
VALUES
('$_POST["name"]',
'$_POST["address"]')";