Im trying to swap the values if taken already but its not working
heres the code:
<?php
ob_start();
require_once("../session.php");
require_once("../functions.php");
require_once("../../includes/connection.php");
include_once("../../includes/header.php");
confirm_logged_in();
if(isset($_GET['cat_id']))
{
$category_id = $_GET['cat_id'];
$result = get_specific_category($category_id);
while($row = mysql_fetch_array($result))
{
$category_name = $row['category_name'];
$position = $row['position'];
$visible = $row['visible'];
}
}
if(isset($_POST['Submit']))
{
$errors = verify_null_values(array('Name', 'Position'));
if(empty($errors))
{
$category_id = $_POST['cat_id'];
$category_name = mysql_prep($_POST['Name']);
$position = $_POST['Position'];
$visible = $_POST['Visible'];
$want_position = $_POST['Position']; //1
$query = "SELECT *
FROM categories
WHERE position='{$category_id}'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$category_name = $row['category_name'];
$orig_position = $row['position'];
$visible = $row['visible'];
}
// as init value
$new_position = $orig_position; //4
//error
$move_position_of_this = ($new_position - 1);
echo $new_position;
if($orig_position > $want_position)
{
// data has been preserved above
// as in temp = data
//$move_position_of_this = ($orig_position - 1); //2
//move existing categories position down
while($move_position_of_this >= $want_position)
{
//take the new position
$query_move_positions = "UPDATE categories
SET position='{$new_position}'
WHERE position='{$move_position_of_this}'";
$result = mysql_query($query_move_positions);
$new_position--; //2
$move_position_of_this--; //1
}
}
//correct
$query = "UPDATE categories
SET
category_name='{$category_name}',
position='{$position}',
visible='{$visible}'
WHERE
category_id='{$category_id}'";
$result = mysql_query($query);
//redirect_to("category_view.php");
}
else
{
output_errors($errors);
}
}
?>
<h1>Edit Category</h1>
<form action="category_edit.php" method="post">
Category Name: <input name="Name" type="text" value="<?php echo $category_name ?>" /> <br />
Position: <select name="Position">
<?php
$result_category = get_categories();
$num_rows = mysql_num_rows($result_category);
for ($count = 1; $count <= $num_rows; $count++)
{
echo "<option value=\"{$count}\"";
if($position == $count)
{
echo " selected";
}
echo ">{$count}</options>";
}
?>
</select>
<br />
Visible: <input name="Visible" type="radio" value="1"
<?php if($visible == 1){echo " checked";}?> /> Yes
<input name="Visible" type="radio" value="0"
<?php if($visible == 0){echo " checked";}?>/> No<br />
<input name="cat_id" type="hidden" value="<?php echo $category_id ?>" />
<input name="Reset" type="reset" value="Reset" />
<input name="Submit" type="submit" value="Update" />
</form>
<?php
include_once("../../includes/footer.php");
ob_flush();
mysql_close();
?>
any reason why its not working so far?
thanks!