Problem with my mysql adding form
Posted: Thu Nov 25, 2004 3:11 pm
Im getting the odd error "Unknown column 'test' in 'field list'" when i try to use it. (thats when i put test in) . I cant really see the problem with it all but im really rusty with php so ive probably done somthing stupid.
Heres my code
Function for database queries
Heres where its called
And that is called by a simple html form. If you want to try it out for yourself its here http://www.kzar.co.uk/project
Heres my code
Function for database queries
Code: Select all
<?php
function db_query ($result_wanted, $sql)
{
$dbhost = "localhost";
$dbuser = "censored";
$dbpass = "censored";
$dbname = "censored";
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
or die('counter CONNECT error: '.mysql_errno().', '.mysql_error());
mysql_select_db($dbname,$conn) or die( "Unable to select database");
$result = mysql_query($sql, $conn);
if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}
mysql_close($conn);
if ($result_wanted == true)
{
return $result;
mysql_free_result($result);
}
}
?>Code: Select all
<?php
include('includes/header.txt');
include('db.php');
$subjectname = $_POST['subjectname'];
if ($subjectname == '')
{
echo("<b>You forgot to fill in all of the form.</b><br><br>");
include('includes/subjectform.txt');
}
else
{
echo("<b>You forgot to fill in all of the form.</b><br><br>");
db_query(false,"INSERT INTO tt_subjects (SubjectName)
VALUES ($subjectname)");
}
include('includes/footer.txt');
?>