Currently I have a problem with one of my queries - it seems not to be inserting any of the values into my database. Below is the code I am using for a form submitting.
<?php
if (empty($_POST) === false) {
$assignment_data = array(
'title' => $_POST['title'],
'number' => $_POST['number'],
'weighting' => $_POST['weight'],
'handout' => $_POST['handout'],
'handin' => $_POST['handin'],
'feedback' => $_POST['feedback'],
'wordcount' => $_POST['wordcount'],
'brief' => $_POST['brief'],
'sub_details' => $_POST['details'],
'add_note' => $_POST['notes']
);
create_assignment($assignment_data);
//header('Location: modules.php');
//exit();
}
function create_assignment($assignment_data) {
array_walk($assignment_data, 'array_sanitize');
$fields = '`' . implode('`, `', array_keys($assignment_data)) . '`';
$data = '\'' . implode('\', \'', $assignment_data) . '\'';
$query = mysql_query("INSERT INTO `assignments` ($fields) VALUES ($data)");
echo $fields;
echo $data;
$test = mysql_query($query) or die(mysql_error());;
print $test;
}
?>
I am getting this as the result from entering information into the form and submitting it:
`title`, `number`, `weighting`, `handout`, `handin`, `feedback`, `wordcount`, `brief`,
`sub_details`, `add_note`
'Dream Design', '2', '20', '07/01/2014', '08/01/2014', '08/01/2014', '2', 'asd',
'asdasd', 'asdasdasd'
Query was empty.
The information is being placed in the $fields and $data variables but seems to be not running the query... Nothing is being inserted into my database.
Any help or assistance is greatly appreciated.
mysql_error()??assignments($fields) VALUES ($data)"); - you are using mysql_query twice.