troubleshooting Question

Refreshing a page after updating data in mysql

Avatar of aphix
aphix asked on
PHP
16 Comments1 Solution254 ViewsLast Modified:
Hey,

I have the following code for one of my admin pages, there is a link in the page "show" and "hide" when these are clicked it changes an entry in the table from 0-1 or 1-0. If you look at the code depending on what that entry is set to, determines certain contents on the page. Like the colour of a row. etc.

Ideally what i want to happen is when the "show" or "hide" link is clicked, the entry is updated, then the page is refreshed to show the changed data.

I have tried to use "header("Location: " . $_SERVER['php_SELF']); " however this doesnt work everytime.. it appears to refresh the page, but the contents on the page doesnt always change.

Does anyone have any ideas?

Rob

<?
include("db.php");
if(!isset($cmd)){}
$result = mysql_query("select * from make order by mak_make");
?>
<html>
<head>
</head>
<center>  
  <table width="325" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="60" height="19" align="left"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif"> ID</font></strong></td>
      <td width="180" align="left" valign="middle"><strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Make</font></strong></td>
      <td width="85" align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Options</strong></font></td>
    </tr>
      <?php while($row=mysql_fetch_array($result))
               { ?>
    <tr>
      <td><font<?php

if ($row["mak_visible"] == "1") {?> color="#000000"<?php }
else {?> color="#999999"<?php }

?> size="1" face="Verdana, Arial, Helvetica, sans-serif"><?php echo "$row[mak_id]";?></font></td>
     
<td><font<?php

if ($row["mak_visible"] == "1") {?> color="#000000"<?php }
else {?> color="#999999"<?php }

?> size="1" face="Verdana, Arial, Helvetica, sans-serif"><?php echo "$row[mak_make]";?></font></td>
     
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="add_make.php?cmd=delete&mak_id=<?php echo "$row[mak_id]";?>">delete</a> - <?php

if ($row["mak_visible"] == "1") {?>
<a href="add_make.php?cmd=hide&mak_id=<?php echo "$row[mak_id]";?>">hide</a>
<?
}

else {?>
<a href="add_make.php?cmd=show&mak_id=<?php echo "$row[mak_id]";?>">show</a>
<?php
}

?></font></td>
    </tr>
     
    <?php } ?>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr align="center" bgcolor="#CCCCCC">
      <td height="20" colspan="3"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Add a Make</strong></font></td>
    </tr>
    <tr align="center" bgcolor="#CCCCCC">
      <td height="39" colspan="3"><form method="post" action="add_make.php?cmd=add">
          <input type="hidden" name="mak_id" value="">
          <input type="text" name="mak_make" size="30">
          <input name="submit" type="submit" value="Add">
        </form></td>
<?php

      if($_GET["cmd"]=="add")
      {
      $sqlquery = "INSERT INTO make VALUES('$mak_id','$mak_make')";
      $results = mysql_query($sqlquery);
      echo "$mak_make - Added!";
      }
                  
      if($_GET["cmd"]=="show")
      {
      $sqlquery_show = "UPDATE make SET mak_visible = '1' WHERE mak_id = '$mak_id'";
      $result_show = mysql_query($sqlquery_show);
      header("Location: " . $_SERVER['php_SELF']);
      }
                  
      if($_GET["cmd"]=="hide")
      {
      $sqlquery_show = "UPDATE make SET mak_visible = '0' WHERE mak_id = '$mak_id'";
      $result_show = mysql_query($sqlquery_show);
      header("Location: " . $_SERVER['php_SELF']);
      }
            
      if($_GET["cmd"]=="delete")
      {
    $sql = "DELETE FROM make WHERE mak_id=$mak_id";
    $result = mysql_query($sql);
      echo "$mak_make - Deleted!";
      }
      
?>
    </tr>
  </table>  
</center>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 16 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros