My hosting company just turned off register_globals and I’m having some problems with my codes. I have a big website with hundreds of pages of codes.
I’m not able to bypass this with htaccess, so I have to start redoing some of my codes.
I have an edit form that when called it will display a list of all the entries in a particular database table (mysql) with a link to edit an entry. When you click on a link the information is displayed in a form to edit it. When you submit it’s updated in the database.
You can also choose to delete the entry by clicking on a delete link. All this is handled on one page. Here’s the code:
[code=php]include(“includes/dbconnect.php”);
if(!isset($cmd)) {
$result = mysql_query(“select * from links order by id desc”);
while($r = mysql_fetch_array($result)) {
$name = stripslashes($r[‘name’]);
$link = stripslashes($r[‘link’]);
$type = stripslashes($r[‘type’]);
$id = $r[‘id’];
echo ”
<!–$id–> $name
<a href=’edit_link.php?cmd=edit&id=$id’>Edit</a>
<a href=’edit_link.php?cmd=delete&id=$id’>Delete</a>
“;
}
}
if($_GET[“cmd”]==”edit” || $_POST[“cmd”]==”edit”)
{
if (!isset($_POST[“submit”]))
{
$id = $_GET[“id”];
$sql = “SELECT * FROM links WHERE id=’$id'”;
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$name = stripslashes($myrow[‘name’]);
$link = stripslashes($myrow[‘link’]);
$type = stripslashes($myrow[‘type’]);
$id = $myrow[‘id’];
echo ”
<form action=’edit_link.php’ method=’post’>
–form edit entries–
<input type=’hidden’ name=’cmd’ value=’edit’>
<input type=’submit’ name=’submit’ value=’submit’>
</form>
“;
}
if ($_POST[“$submit”]) {
$name = escape_data($_POST[‘name’]);
$link = escape_data($_POST[‘link’]);
$type = escape_data($_POST[‘type’]);
$sql = “UPDATE links SET name=’$name’, link=’$link’, type=’$type’ WHERE id=’$id'”;
$result = mysql_query($sql);
echo “Link updated”;
}
}
if($_GET[“cmd”]==”delete”) {
$sql = “DELETE FROM links WHERE id=’$id'”;
$result = mysql_query($sql);
echo “Deleted”;
}
When the page is first called the database entry is displayed in a list and the list is all that is displayed. This is good. When you click on an edit link next to a name the form to edit the information is suppose to appear and the list is suppose to disappear. The form appears but the list remains.
Also, when you make the changes and hit submit the form is gone and the list is still there. I should be getting a message saying that the information has been updated or not, but I’m not – and the information is not being updated.
This edit form worked fine before register_globals was disabled but now it isn’t.
What changes should I make to fix this?
Thanks.
Alan P