I have a form where the user enters the url they want and proceeds to the next step. This is all done with no page refresh, so I'm relying on Ajax to send the information. When the user submits the url they want, they are allowed to go the next part. The user also has the option to go back to the url page and change their url. I know how to insert the url successfully, but I don't know how to update the entry with the new url. I tried this, but it's not working:
$prevUrl;
$newUrl;
if ((isset($_POST["url"]))
{
$newUrl = $_POST["url"];
if ($prevUrl == "")
{
$db->query("INSERT INTO Articles (`url`) VALUES ('$newUrl')");
$prevUrl = $newUrl;
}
else
{
$db->query("UPDATE Articles SET url = '$newUrl' WHERE url = '$prevUrl'");
$prevUrl = $newUrl;
}
}
How can I make it so that when the entry is updated, it gets updated based on what the previous url was?
What's wrong: When I go back to update the url, the url doesn't get updated with the new one. My WHERE clause is not executing successfully. It is as though the $prevUrl variable is empty. I figure that since PHP is server side, whatever variables are shown upon page refresh, those are the variables and they can't change. Since $prevUrl is empty at first, the WHERE statement is probably doing something like this WHERE url = "". I'm not sure if that's it though. There was no exception error or any kind of fatal error.