I have a form within index.php which sends the data to add2DB.php for processing
Code: Select all
<form action="add2DB.php" method="POST">
<input type="text" name="txtFrom" value="" />
<input type="text" name="txtTo" value="" />
</form>
add2DB.php
Code: Select all
<?php
require('index.php');
$dbHost = "localhost:3306";
$database = "myTest";
$username = "root";
$password = "enter";
$connection = mysql_connect($dbHost, $username, $password);
if (!$connection)
{
die("Could not connect: <br>". mysql_error() );
}
//Get the data from index.php
$to = $_POST[txtTo];
$from = $_POST[txtFrom];
mysql_select_db($database);
mysql_query("INSERT INTO Map(`from`, `to`) VALUES ($from, $to)");
echo "$from and $to have been added. <br />";
static $count = 1;
if ($count = 1)
{
echo "$count record added.";
}
else
{
echo "$count records added.";
}
mysql_close($connection);
?>
echo "$from and $to have been added. <br />"; produces the expected values so I assume $to = $_POST[txtTo] and $from = $_POST[txtFrom] is working as expected. That is the values for txtTo and txtFrom are being passed from index.php to add2DB.php.
I also tried the SQL query outside of PHP and it seems to work but nothing is being entered into the database when I run this program.
Also my count of records doesn't work but that's an aside for now.
I'm sure that I am missing something valuable here. Any help would be greatly appreciated.
Thanks