Jump to content
MakeWebGames

Update Pages


Dragon Blade

Recommended Posts

Hey all, I have a script here.

It doesn't update the tables? Everything seems fine?

 

<?php

include"globals.php";

global $db, $ir, $c, $h, $userid, $set;

if (!isset($_GET['ID']))
{
   $_GET['ID'] = '';
}


$_GET['ID'] = abs((int) $_GET['ID']);

if($_POST) {
foreach ($_POST as $k => $v)
       {
           mysql_query(
                   "UPDATE pages
                    SET $k ='$v'
                    WHERE page_id =".$_GET['ID']);
       }

stafflog_add("Edited Index Page");


  echo '
       Index Page Updated!<br />
       > <a href="staff_index.php">Staff Index</a>
          ';
   $h->endpage();
   exit;
}

if(!$_GET['ID']) {
   echo '
   <b><u>Editing Index Page</u></b>


   Please select the page you wish to edit below.


   <table width="70%" class="table" cellpadding="5" cellspacing="1">
       <tr>
           <th width="50%">Page ID</th>

       </tr>
       <tr>

           <td style="text-align: center;">
               <form action="'.basename($_SERVER['SCRIPT_FILENAME']).'" method="get">
               '.page_dropdown($c, 'ID').'

               <input type="submit" value="Edit" />
               </form>
           </td>
       </tr>
   </table><br /><br />
   ';
   $h->endpage();
   exit;
}

function showTable($variable) {
   if ($variable === true) {
       return 'true';
   } else if ($variable === false) {
       return 'false';
   } else if ($variable === null) {
       return 'null';
   } else if (is_array($variable)) {
       $html = '


       <table width="80%" class="table" cellpadding="5" cellspacing="1" style="text-align: left;">
       <tr><th colspan="2">Updating page ['.$_GET['ID'].'] <div style="float: right;"><a href="staff_index.php">Back</a></div></th></tr>
       <tr><th width="20%" style="text-align: left;">Field</th><th style="text-align: left;">Value</th></tr>';
       foreach ($variable as $key => $value) {
           $value = showTable($value);
           $hide = array('page_id');
           if(!in_array($key, $hide)) {
               $html .= '<tr><td style="text-align: left;">'.ucfirst($key).'</td>
               <td style="text-align: left;">
                   <input type="text" name="'.$key.'" value="'.$value.'" size="70">
               </td></tr>';
           }
       }
       return $html;
   } else {
       return strval($variable);
   }
}

$ro = mysql_query("SELECT * FROM pages WHERE page_id=".$_GET['ID']);
if(!mysql_num_rows($ro)) {
   echo 'No Page Found<br />

   <a href="staff_index.php">>Staff Index</a>';
   $h->endpage();
   exit;  
}
$r = mysql_fetch_assoc($ro);

echo '<form action="staff_pageupdate.php" method="post">';
echo showTable($r);
echo '<tr><td colspan="2"><input type="submit" value="Save new updates" /></td></tr></form>
</table><br /><br />


';
$h->endpage();
Link to comment
Share on other sites

For one why don't you give your submit buttons a name? This you you can check for a post request by an input name. Now I forget which one is more dominant between get and post but you may just be checking to see if therr is any post request method and post may just be what you get once you click a link.

Also, what's with the globals? you don't need to look for global variables because your not inside a function or a method of any sort.

So try these and post back the results

EDIT:

I wouldn't recommend looping through each post request because you will be grabbing stuff you probably don't want and it may not be working because you are trying to update columns that you don't have since you are grabbing each post request

EDIT 2:

I don't know why I'm catching stuff after a submit but I think you want your returns to not be strings in you show tables function. I think you can't them to be (bool)contants

Edited by KyleMassacre
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...