I am trying $_POST an UPDATE to the following mysql table:
Note: there are 3 dropdowns: status, category and access
app_generalData
---------------
app_id
table
status_id
category_id
tags
access_id
Resulting tests with print_r($_POST) and echo(s) 's ensure the form $_POST is working:
Array (
[MAX_FILE_SIZE] => 100000
[app_id] => 1
[title] => Nothing Special
[status] =>
[category] =>
[tags] => new tag
[access] =>
[update] => Update )
Data from the form.
- ID: 1
- Title: Nothing Special
- Status:
- Category:
- Tags: new tag
- Access:
Resulting Error message:
Error querying database for General Data.
Desired result(s):
- $_POST items updating in the db
Snippet for UPDATE:
// Post the UPDATE to app_generalData
if (isset($_POST['update'])) {
// print_r($_POST);
// echo '<br />';
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Grab the data from the POST
// General Data
$app_id = mysqli_real_escape_string($dbc, trim($_POST['app_id']));
$title = mysqli_real_escape_string($dbc, trim($_POST['title']));
$status = mysqli_real_escape_string($dbc, trim($_POST['status']));
$category = mysqli_real_escape_string($dbc, trim($_POST['category']));
$tags = mysqli_real_escape_string($dbc, trim($_POST['tags']));
$access = mysqli_real_escape_string($dbc, trim($_POST['access']));
// Confirm success with the user
echo '<h1>Data from the form.</h1><br />';
echo 'ID: ' . $app_id .'<br />';
echo 'Title: ' . $title .'<br />';
echo 'Status: ' . $status .'<br />';
echo 'Category: ' . $category .'<br />';
echo 'Tags: ' . $tags .'<br />';
echo 'Access: ' . $access .'<br />';
echo '<br />';
// Write the data to the database
$query = "UPDATE app_generalData
SET title = $title,
status_id = $status,
category_id = $category,
tags = $tags,
access_id = $access
WHERE app_id = $app_id
";
mysqli_query($dbc,$query)
or die('Error querying database for General Data.');
// close MySQL
mysqli_close($dbc);
exit();
}
else {
echo 'Please enter all details below.';
}