Hi have a dropdown list populated from mysql. I want to be able to select a value from the dropdown list, submit it, and have the value increase by 1. Here is the code I have. I can get the code to submit but not increase by 1.
categoreies_modify.php file:
<form action=“?” method=“POST”>
<table cellspacing=“5” cellpadding=“1” border=“0”>
<tr>
<td>
Change Parent Category To:
</td>
<td>
<select name=“location” id=“location”>
<?php foreach ($categories as $loc): ?>
<option value=“<?php htmlout($loc[‘parentid’]); ?>”><?php htmlout($loc[‘cattitle’]); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type=“hidden” name=“id” value=“<?php htmlout($id); ?>” />
<input type=“submit” value=“Update” />
</td>
</tr>
</table>
</form>
##################
snippet from index.php file (controller):
//populates the edit fields (not show in the categories_modify.php snippet) //and the dropdown form
if (isset($_POST[‘action’]) and $_POST[‘action’] == ‘Edit’)
{
include $_SERVER[‘DOCUMENT_ROOT’] . ‘./includes/db.inc.php’;
{
$id = mysqli_real_escape_string($link, $_POST[‘id’]);
$sql = “Select id, cattitle, orderby, caturl, catdesc, parentid from categories where id = ‘$id’”;
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = ‘Error fetching category details.’;
include ‘error.php’;
exit();
}
$row = mysqli_fetch_array($result);
$pagetitle = 'Edit Category';
$action = 'editform';
$id = $row['id'];
$cattitle = $row['cattitle'];
$orderby = $row['orderby'];
$caturl = $row['caturl'];
$catdesc = $row['catdesc'];
$button = 'Update';
$locate = "Select id, cattitle, parentid from categories order by cattitle asc";
$res = mysqli_query($link, $locate);
if (!$res)
{
$error = 'Error fetching category details.';
include 'error.php';
exit();
}
while ($locat = mysqli_fetch_array($res))
{
$categories[] = array('id' => $locat['id'], 'cattitle' => $locat['cattitle'], 'parentid' => $locat['parentid']);
}
}
include ‘categories_modify.php’;
exit();
}
//gets the submitted values from the dropdown form
if (isset($_POST[‘location’]))
{
include $_SERVER[‘DOCUMENT_ROOT’] . ‘./includes/db.inc.php’;
$id = mysqli_real_escape_string($link, $_POST['id']);
$parentid = mysqli_real_escape_string($link, $_POST['parentid']);
++$parentid;
$sql = "Update categories set
parentid = '$parentid',
where id = '$id'";
if (!mysqli_query($link, $sql))
{
$error = 'Error updating categories.';
include 'error.php';
exit();
}
header('Location: .');
exit();
}
the purpose of this is to be able to put my nav links into subcategories. Thanks for looking at this. I have been making changes and editing the code for about 2 weeks and haven’t got it figured out.