I have a html form and would like to insert its input to a mysql database using a php file. i am new to php , the version i have is Php version = 5.2.17
PhpMyAdmin version = 3.4.6 and Mysql version 5.5.16
I have been trying for 2 long weeks to figure which php script will allow my data to be added to the mysql table. i found a script and it does submit the data however it does not submit the data entered into the form. See my script:
FIRST PHP I TRIED:
<?php
/ mysql hostname /
$hostname = 'localhost';
/ mysql username /
$username = 'root';
/ mysql password /
$password = 'root';
/ mysql database name /
$dbname = 'spierform';
/ create a new mysqli object with default database/
$mysqli = @new mysqli($hostname, $username, $password, $dbname);
/ check connection /
if(!mysqli_connect_errno())
{
/ if we are successful /
echo 'Connected Successfully<br />';
/*** sql to INSERT a new record ***/
$sql = "INSERT INTO feedback (FirstName, LastName, Department, Technician, TicketNo, Rating_Tech, Rating_Team, Comments)
VALUES ('FirstName', 'LastName', 'Department', 'Technician', 'TicketNo', 'Rating_Tech', 'Rating_Team', 'Comments')";
if($mysqli->query($sql) === TRUE)
{
echo 'New record created successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
/*** close connection ***/
$mysqli->close();
}
else
{
/ if we are unable to connect /
echo 'Unable to connect';
exit();
}
?>
THE SECOND PHP SCRIPT I TRIED
<?php
define('DB_NAME', 'spierform');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use' . DB_NAME. ': ' . mysql_error());
}
$FirstName = $POST['FirstName'];
$LastName = $POST['LastName'];
$Department = $POST['Department'];
$Technician = $POST['Technician'];
$TicketNo = $POST['TicketNo'];
$Rating_Tech = $POST['Rating_Tech'];
$Rating_Team = $POST['Rating_Team'];
$Comments = $POST['Comments'];
$sql = "INSERT INTO feedback (FirstName, LastName, Department, Technician, TicketNo, Rating_Tech, Rating_Team, Comment) VALUES ('$FirstName', '$LastName', '$Department', '$Technician', '$TicketNo', '$Rating_Tech', '$Rating_Team', '$Comments')";
{
die('Error' . mysql_error());
}
mysql_close();
?>
I hope someone can help me and guide me in the right direction , i am so frustrated that i still cannot get the data into the db table
thank you for your assistance and advice in advancce