What you posted in your (now deleted) comment is that your form contains name="long"
and name="lat"
Those don't match your:
$latitude=$_POST['Lat']; // uppercase L
$longitude=$_POST['Long']; // uppercase L
$start_point=$_POST['s_point'];
$end_point=$_POST['e_point'];
Change it to:
$latitude=$_POST['lat']; // lowercase l
$longitude=$_POST['long']; // lowercase l
$start_point=$_POST['s_point'];
$end_point=$_POST['e_point'];
- PHP variables are case-sensitive
Sidenote: Your present code is open to SQL injection. Use prepared statements, or PDO
Edit/Rewrite:
<?php
session_start();
$link = mysqli_connect("localhost","root","123456","db_mmw") or die ("Error" .mysqli_errno($link));
// connection to mysql
$latitude=$_POST['lat'];
$longitude=$_POST['long'];
$start_point=$_POST['s_point'];
$end_point=$_POST['e_point'];
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO tbl_route (latitude,longitude,start_point,end_point) VALUES ('".$latitude."','".$longitude."','".$start_point."','".$end_point."')";
if (!mysqli_query($link,$sql))
{
die('Error: ' . mysqli_error($link));
}
mysqli_close($link);
?>
This is another issue:
<input type="submit" name="Define Route" value="Define Route"
is outside your form which will prevent it from working, plus there was a missing >
and should have read as:
<input type="submit" name="Define_Route" value="Define Route">
I changed it name="Define Route"
to name="Define_Route"
just in case.
<div class ="form">
<form method="post" action=""><br> <table border="0">
<tr> <td>Start Point</td><td>
<input type="text" name="s_point"></td> </tr> <tr>
<td>End Point</td><td> <input type="text" name="e_point"></td> </tr>
<tr> <td> Latitude </td><td> <input type="text" name="lat"></td> </tr>
<tr> <td> Longitude </td><td> <input type="text" name="long"></td> </tr> </table>
<input type="submit" name="Define_Route" value="Define Route">
</form>
<br><br> </div>
</div>
Complete rewrite with form that worked for me.
Using VARCHAR(255)
for all four columns.
(Use in one file)
<?php
session_start();
$link = mysqli_connect("localhost","root","123456","db_mmw") or die ("Error" .mysqli_errno($link));
if(isset($_POST['Define_Route'])){
// connection to mysql
$latitude=$_POST['lat'];
$longitude=$_POST['long'];
$start_point=$_POST['s_point'];
$end_point=$_POST['e_point'];
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO tbl_route (latitude,longitude,start_point,end_point) VALUES ('".$latitude."','".$longitude."','".$start_point."','".$end_point."')";
if (!mysqli_query($link,$sql))
{
die('Error: ' . mysqli_error($link));
}
} // brace for if(isset($_POST['Define_Route']))
mysqli_close($link);
?>
<div class ="form">
<form method="post" action=""><br> <table border="0">
<tr> <td>Start Point</td><td>
<input type="text" name="s_point"></td> </tr> <tr>
<td>End Point</td><td> <input type="text" name="e_point"></td> </tr>
<tr> <td> Latitude </td><td> <input type="text" name="lat"></td> </tr>
<tr> <td> Longitude </td><td> <input type="text" name="long"></td> </tr> </table>
<input type="submit" name="Define_Route" value="Define Route">
</form>
<br><br> </div>
</div>