Looks pretty good to me.
This is the way I would do it.
Code: Select all
<?PHP
$db = mysql_connect("localhost", "root") or die("could not connect: " . mysql_error());
mysql_select_db("dissertation", $db) or die("could not connect: " . mysql_error());
//new code starts here
$Company = $_POSTї'Company'];
$Name = $_POSTї'Name'];
$Code = $_POSTї'Code'];
$Results = $_POSTї'Results'];
$Dept = $_POSTї'Dept'];
$Mailing = $_POSTї'Mailing'];
$Email = $_POSTї'Email'];
$Gender = $_POSTї'Gender'];
$Age = $_POSTї'Age'];
//new code ends here
$sql = "INSERT INTO participants (Company, Name, Code, Results, Dept, Mailing, Email, Gender, Age) VALUES ('$Company','$Name', '$Code', '$Results', '$Dept', '$Mailing', '$Email', '$Gender', '$Age')";
?>
<html>
<body>
<?php
if (@mysql_query ($sql)){
echo("<p>Insert complete</p>");
}else{
echo ("<p>couldn't insert into table: " . mysql_error() . "</p>");
}
?>
</body>
</html>
or you can do it like this
Code: Select all
<?PHP
$db = mysql_connect("localhost", "root") or die("could not connect: " . mysql_error());
mysql_select_db("dissertation", $db) or die("could not connect: " . mysql_error());
$sql = "INSERT INTO participants (Company, Name, Code, Results, Dept, Mailing, Email, Gender, Age) VALUES ('".$_POSTї'Company']."','".$_POSTї'Name']."', '".$_POSTї'Code']."', '".$_POSTї'Results']."', '".$_POSTї'Dept']."', '".$_POSTї'Mailing']."', '".$_POSTї'Email']."', '".$_POSTї'Gender'].", '".$_POSTї'Age']."')";
?>
<html>
<body>
<?php
if (@mysql_query ($sql)){
echo("<p>Insert complete</p>");
}else{
echo ("<p>couldn't insert into table: " . mysql_error() . "</p>");
}
?>
</body>
</html>