Redirect depending on category chosen

You never initialize the value in $url. Test the value in $swapcategory. When there is no match, $url is empty and that may be the problem. This comment is false:

// $url now contains our new success page. Let's update the form setting.

It should say:

// $url may contain our new success page or it may be unset.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)