Jump to content

elite_prodigy

Members
  • Posts

    158
  • Joined

  • Last visited

    Never

Posts posted by elite_prodigy

  1. PHP may be a tad more relenting, provided you explode the file based on spec.... Change \r\n to \n and you should get this:

    array (
      'COL1' => 
      array (
        0 => 'val1g',
        1 => 'val1f',
        2 => 'val1e',
        3 => 'val1d',
        4 => 'val1c',
        5 => 'val1b',
        6 => 'val1a',
        7 => NULL,
      ),
      'COL2' => 
      array (
        0 => 'val2g',
        1 => 'val2f',
        2 => 'val2e',
        3 => 'val2d',
        4 => 'val2c',
        5 => 'val2b',
        6 => 'val2a',
        7 => NULL,
      ),
      'COL3' => 
      array (
        0 => 'val3g',
        1 => 'val3f',
        2 => 'val3e',
        3 => 'val3d',
        4 => 'val3c',
        5 => 'val3b',
        6 => 'val3a',
        7 => NULL,
      ),
      'COL4' => 
      array (
        0 => 'val4g',
        1 => 'val4f',
        2 => 'val4e',
        3 => 'val4d',
        4 => 'val4c',
        5 => 'val4b',
        6 => 'val4a',
        7 => NULL,
      ),
      'COL5' => 
      array (
        0 => 'val5g',
        1 => 'val5f',
        2 => 'val5e',
        3 => 'val5d',
        4 => 'val5c',
        5 => 'val5b',
        6 => 'val5a',
        7 => NULL,
      ),
    )

     

    Probably because you're on Linux? I'm on Windows, but I've switched to the file() function anyway. :P

     

    So, now it does seem to work. THe issue was that I was not assigning the final $table to the Object's $table, so $table was going out of scope for the rest of the class.

     

    Everything works in the OO implementation now except for the sorting which now seems to be broken.

  2. Okay, in my first post, I posted some non Object Oriented code that actually does work fine.

     

    When I attempted to move the code over to an Object Oriented format, it broke. I didn't re-write the code, I just copy pasted with a few minor changes to variable declarations to seemingly make it work, however it does not work, at all, in the Object Oriented version.

     

  3. Notice: Undefined offset: 1 in E:\wamp\www\Mike Broudy\tableproc.oop.php on line 26
    
    Warning: array_multisort() [function.array-multisort]: Argument #4 is expected to be an array or a sort flag in E:\wamp\www\Mike Broudy\tableproc.oop.php on line 55
    
    array (
      'COL1' => 
      array (
        0 => NULL,
      ),
      'COL2' => NULL,
      'COL3' => NULL,
      'COL4' => NULL,
      'COL5' => NULL,
    )

     

    It seems the issue is lying in that $table is not being accessed later within the class when GetSortedTable is called.

     

    The underlying code in the two separate scripts is nearly identical, if not entirely for the most part, so in theory it *should* be working. But it's not, which I don't understand.

     

  4. I am trying to write a solution which sorts some output from one of our old legacy applications but I'm having some problems. I wrote a non OO implementation that works, albeit with some warnings but that's fine because at least I'm getting the result I want. Now that I've tried to move it over to an OO implementation nothing I want is happening, if anything but errors at all.

     

    This is a sample file I wrote for testing purposes:

     

    COL1	COL2	COL3	COL4	COL5
    val1a	val2a	val3a	val4a	val5a
    val1b	val2b	val3b	val4b	val5b
    val1c	val2c	val3c	val4c	val5c
    val1d	val2d	val3d	val4d	val5d
    val1e	val2e	val3e	val4e	val5e
    val1f	val2f	val3f	val4f	val5f
    val1g	val2g	val3g	val4g	val5g

     

    And here is the non OO code that works:

    <?php
    
    $file = file_get_contents("tableinput.txt"); 
    
    $table = array();
    $temp_table = array();
    $file = explode ("\r\n", $file); //break the input into individual lines
                                     //we assume file was written on Windows machine (can easily change \r\n to simply \r for Linux)
    
    foreach ($file as $line) { 
      
      $line = explode ("\t", $line);
    
      array_push($temp_table, $line); 
      
    }
    
    for($i = 0; $i < sizeof($temp_table); $i++){  
    $col_array = array();                                                            
    for($j = 1; $j < sizeof($temp_table); $j++){ 
    	array_push($col_array, $temp_table[$j][$i]);
    }
    if($temp_table[0][$i] != "")
    	$table[$temp_table[0][$i]] = $col_array;
    }
    //sort array based on data in COL1 in descending format.
    //Since input data is already sorted in ascending order,
    //this is the easiest way to show that this is effective
    array_multisort($table['COL1'], SORT_DESC, SORT_STRING, $table['COL2'], $table['COL3'], $table['COL4'], $table['COL5']); 
    echo "<pre>"; var_export($table); echo "</pre>"; //dump the sorted array to the screen (proof of concept)
    
    
    ?>
    

     

    And here, alas, is the code that for reasons that are beyond me, does not.

     

    <?php
    class SortTable {
    public $table = array();
      
      public function __construct ($filepath) {
                  
        $file = file_get_contents($filepath); 
    
        $temp_table = array();
        $file = explode ("\r\n", $file); //break the input into individual lines
                                         //we assume file was written on Windows machine (can easily change \r\n to simply \r for Linux)
        
        foreach ($file as $line) { 
          
          $line = explode ("\t", $line);
        
          array_push($temp_table, $line); 
          
        }
        
    
        for($i = 0; $i < count($temp_table); $i++){ 
    
        	$col_array = array(); 
        	for($j = 1; $j < count($temp_table); $j++){ 
        		array_push($col_array, $temp_table[$j][$i]);
        	}
        	if($temp_table[0][$i] != "")
        		$this->table[$temp_table[0][$i]] = $col_array;
        }
    
      
      }
      
      public function GetSortedTable ($SortCol, $params) {
      
        /*$ParamSet = Array();
      
        array_push ($ParamSet, &$this->table[$SortCol]); 
        array_push ($ParamSet, explode(',', $params));
        
        foreach ($this->table as $column) {
            
            if ($column != $this->table[$SortCol]) {
            
              array_push ($ParamSet, &$column);
            
            } 
            
        } */
        
        //call_user_func_array('array_multisort', $ParamSet);
    
    
        array_multisort ($this->table['COL1'], SORT_DESC, SORT_STRING, $this->table['COL2'], $this->table['COL3'], $this->table['COL4'], $this->table['COL5']);
        
        return $this->table;
      
      }
    
    }
    
    
    $sort = New SortTable("http://root.pixomania.net/table.txt");
    
    $table = $sort->GetSortedTable("COL3", "SORT_DESC, SORT_STRING");
    
    echo "<pre>"; var_export($table); echo "</pre>"; //dump the sorted array to the screen (proof of concept)
    
    ?>

     

     

    Here is the output from the non OO which works. This is exactly what I'm trying to get from the OO version (if I could manage to get rid of those warnings, that would be great, but beggars can sooooo not be choosers.)

     

    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 5 in E:\wamp\www\Mike Broudy\tableproc.php on line 23
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 6 in E:\wamp\www\Mike Broudy\tableproc.php on line 23
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 21
    
    Notice: Undefined offset: 7 in E:\wamp\www\Mike Broudy\tableproc.php on line 23
    
    array (
      'COL1' => 
      array (
        0 => 'val1g',
        1 => 'val1f',
        2 => 'val1e',
        3 => 'val1d',
        4 => 'val1c',
        5 => 'val1b',
        6 => 'val1a',
      ),
      'COL2' => 
      array (
        0 => 'val2g',
        1 => 'val2f',
        2 => 'val2e',
        3 => 'val2d',
        4 => 'val2c',
        5 => 'val2b',
        6 => 'val2a',
      ),
      'COL3' => 
      array (
        0 => 'val3g',
        1 => 'val3f',
        2 => 'val3e',
        3 => 'val3d',
        4 => 'val3c',
        5 => 'val3b',
        6 => 'val3a',
      ),
      'COL4' => 
      array (
        0 => 'val4g',
        1 => 'val4f',
        2 => 'val4e',
        3 => 'val4d',
        4 => 'val4c',
        5 => 'val4b',
        6 => 'val4a',
      ),
      'COL5' => 
      array (
        0 => 'val5g',
        1 => 'val5f',
        2 => 'val5e',
        3 => 'val5d',
        4 => 'val5c',
        5 => 'val5b',
        6 => 'val5a',
      ),
    )

     

    You guys have always been great to me, I learn so much more every time I post here, so here's hoping you guys can point out all my retarded mistakes so I never have to make them again.

     

    --David

     

     

  5. Basically, I need to get a series 0f domains out of a string and store them in an array where they will then be cross-checked on another array, but the details after I get the domain are not nearly as important as getting the domain itself.

     

    I've included a sample of what I would have to extract. (Posting the real data would feel too much like advertising to me and would thus feel tacky.)

     

    sub.domain.com: username
    abc.alphabet.com: qwerty
    example.com: bob
    google.com: qwerty
    mydomain.org: jose
    cia.gov: obama
    *: root
    

     

    I don't care about anything after the ":" (colon), of course I could explode() the string, and cycle through the array and add every other index to the new array, but that just seems messy to me. I was wondering if there is a function I've missed, or if I'm over-thinking things.

     

    I don't expect anyone to write the function for me, I won't stop you if you want to because I can't, an example would be nice, but a simple explanation of the method to use would be awesome and highly apreciated.

     

    -David

     

    (As always, you guys truly do rock!)

  6. Okay, first a touch of a back-story:

     

    Our DNS crashed recently because it's overladden with 96,000+ zones. We are only using around 45,000, maybe a little less. Which means that accounts have not been properly terminated over time and DNS zones have piled up. So, I got the lovely task of sorting through the zones and figuring out which ones are still being used by an account, and which ones need deleting.

     

    It took me about a day to finally stumble upon a way to get every single domain WHM is managing without having to parse through BIND zone files, which would have been awful.

     

    So, now I have the method, but it requires me to authenticate first. So, if any of you have ever used cPanel or WHM (not exactly the greatest, but they are a convenience) then you know that when you try navigate to WHM you get a box that pops up and asks for your user name and password.

     

    This login box is generated by the header() function which send an "Authentication Required" message to the browser or whatever it does.

     

    So, how do I build an HTTP(S) query with the authentication headers built in. I feel like I should know this, but I don't.

     

    I'm not necessarily asking about how to authenticate to cPanel or WHM themselves, but how to build an HTTP(S) query that includes the headers and their values that I need to send.

     

    I'm at a loss at the moment and could really use everyone's help here, you guys and gals are awesome here.

     

    Infinite thanks in advance!

  7. Well, because in the past on this server, for some unknown reason, when I tried to access the local file through it's local filename and directory hierarchy it would attempt to get the file from the directory I was in, and then go down in the subdirectories.

     

    I've fixed the errors, and this works now.

     

    However, could anyone tell me why when I use fwrite() to write to a file opened with mode 'w' all of my quotes are escaped.

     

    This is really messing up the CSS.

  8. Well, once again, PHP decided it was going to hate me with it's very soul. (Can a code engine have a soul? Anyway...)

     

    I'm trying to let people edit my CSS file, well, not everybody, but staff members through the control pannel I've provided for them.

     

    When I try, PHP smiles and slaps me with this error:

     

     

    Warning: filesize() [function.filesize]: stat failed for Resource id #11 in /home/exembar/public_html/team/php/editCSS.php on line 11

     

    Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/exembar/public_html/team/php/editCSS.php on line 11

     

    Here is the code:

     

    <?php
    
    if(!$user->permission('pages')){
    
    error("100", "Access Denied", "You are unable to access this page because you do not have the proper permissions.");
    
    }
    
    $link		= fopen("http://exembarstudios.exofire.net/overall.css", 'r');
    
    $css		= fread($link, filesize($link));
    
    $page->setContent('
    
    				<form name="modCSS" method="post" action="php/doEditCSS.php">
    
    				<textarea class="file" name="css">'.$css.'</textarea>
    
    				</form>
    
    				');
    
    ?>

     

     

    I mode on the css file set to 0644, but have tried changing them to 0664 which had not effect.

     

    As always, you people are amazing, and all of your help is greatly appreciated.

     

    -David

  9. Okay, I accidentally pasted main.php where pageOptions.php should be.

     

    The REAL pageOptions.php

     

    <?php
    error_reporting(E_ALL);
    
    $page->appendOp("index.php", "Add a Page", "id=0&option=0");
    $page->appendOp("index.php", "Edit a Page", "id=0&option=1");
    $page->appendOp("index.php", "Delete a Page", "id=0&option=2");
    
    switch($page->option){
    
    case 0:{
    
    	include 'addPage.php';
    
    	break;
    
    }
    
    case 1:{
    
    	if(isset($_GET['page'])){
    
    		include 'frmEditPage.php';
    
    	}
    	else{
    
    		include 'editPage.php';
    
    	}
    
    }
    
    case 2:{
    
    	include 'deletePage.php';
    
    }
    
    }
    
    ?>

  10. I don't even know what is going on here, but there are several files involved, and I'll post them all here.

     

    Basically, $page->content is not outputting the links to edit each page, and when I type the URL directly that would take me to the page that edits that page, I get a blank screen.

     

    When I echo $page->content from within the file that sets it, it works fine, but when I try to echo it from index.php, it echos nothing.

     

    The only exception here is in editPage.php, if there is more than one record in the database, I get the second record and not the first.

     

    Now, I know the right files are being included and that they are actually retrieving the right information because when I echo directly from the file that sets $page->content, I see exactly what I am supposed to, but at the top of the page.

     

    Thanks everyone, you people are amazing, I have spent the past three days moving this stuff around, trying to fix it, but to no avail. This is my last resort, you guys have saved me in the past, here's hoping it can happen again.

     

     


    This is the index.php file, somewhere in the body, you will see <?php echo $page->content; ?> that's what's not working.

     

    <?php
    
    include 'php/main.php';
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
    <html>
    
    <head>
    <title>Site Control Pannel</title>
    <LINK REL=StyleSheet HREF="overall.css" TYPE="text/css" MEDIA=screen>
    </head>
    
    <body>
    <?php $page->tabs(); ?>
    
    <div class="main">
    
    <div class="nav">
    	<br /><br />
    
    	<?php echo $page->nav; ?>
    
    </div>
    
    <div class="divide">
    
    
    
    </div>
    
    <div class="disp">
    	<br /><br />
    
    	<?php echo $page->content; ?>
    
    </div>
    
    </div>
              
    </body>
    
    </html>

     


    This is the classes.php file, which has all of the classes declared inside.

    <?php
    
    include 'config.php';
    
    class Page{
    
    function Page(){
    
    	if(isset($_GET['id'])){
    
    		$this->id			= $_GET['id'];
    
    	}
    	else{
    
    		$this->id			= 0;
    
    	}
    
    	if(isset($_GET['option'])){
    
    		$this->option		= $_GET['option'];
    
    	}
    	else{
    
    		$this->option		= 0;
    
    	}
    
    	//pre-initialize append-only variables
    	$this->tab_list		= "";
    	$this->options		= "";
    
    }
    
    function tabs(){ //generates the tabs at the top of the box
    
    	$tab_name				= array('Pages',
    									'Staff',
    									'Profile',
    									);
    
    	$tab_loc				= array('index.php?id=0&option=0',
    									'index.php?id=1&option=0',
    									'index.php?id=2&option=0',
    									);
    
    	for($size = 0; $size < count($tab_loc); $size++){
    
    		if($this->id == $size){
    
    			$this->tab_list		.= '<div class="visit_tab_outer">
    										<div class="visit_tab_inner">
    											<a href="'.$tab_loc[$size].'">'.$tab_name[$size].'</a>
    										</div>
    									</div>';
    			continue;
    
    		}
    
    		$this->tab_list		.= '<div class="tab_outer">
    								<div class="tab_inner">
    									<a href="'.$tab_loc[$size].'">'.$tab_name[$size].'</a>
    								</div>
    							</div>';
    
    	}
    
    	echo $this->tab_list;
    
    }
    
    function appendOp($path, $name, $params = ""){ //adds an option to the sidebar of the page
    
    	if(!empty($params)){
    
    		$path				.= "?";
    
    	}
    
    	$this->nav			.= '<a href="'.$path.$params.'">'.$name.'</a>';
    
    }
    
    function setContent($content){ //set the content of the main body of the page
    
    	$this->content		= $content;
    
    }
    
    }
    
    ?>

     


     

    This is the main.php file included in index.php.

     

    <?php
    
    include 'classes.php';
    
    $page			= new Page;
    
    switch($page->id){
    
    case 0:{
    
    	include 'pageOptions.php';
    
    	break;
    
    }
    
    case 1:{
    
    	include 'staffOptions.php';
    
    	break;
    
    }
    
    case 2:{
    
    	include 'profileOptions.php';
    
    	break;
    
    }
    
    }
    
    ?>

     


     

    This is the pageOptions.php file included in main.php

     

    <?php
    
    include 'classes.php';
    
    $page			= new Page;
    
    switch($page->id){
    
    case 0:{
    
    	include 'pageOptions.php';
    
    	break;
    
    }
    
    case 1:{
    
    	include 'staffOptions.php';
    
    	break;
    
    }
    
    case 2:{
    
    	include 'profileOptions.php';
    
    	break;
    
    }
    
    }
    
    ?>

     


     

    This is the editPage.php file included in pageOptions.php

     

    <?php
    
    include 'config.php';
    
    mysql_select_db("exembar_site");
    
    $query 				= "SELECT * FROM `navigation`";
    
    $result 			= mysql_query($query);
    
    $body 				= "";
    
    while($pages = mysql_fetch_array($result)){
    
    $disp 				= $pages['display'];
    $id 				= $pages['id'];
    
    $body 				.= '<a href="'.$root.'index.php?id=0&option=1&page='.$id.'">'.$disp.'</a>';
    
    }
    
    $page->setContent($body); //if I could kick this, I would
    echo $page->content; //this works, but it echoed above my page, and looks awful
    
    ?>

     


     

    This is frmEditPage.php included in pageOptions.php

     

    <?php
    
    include 'config.php';
    mysql_select_db("exembar_site");
    
    $query 			= "SELECT * FROM `navigation` WHERE `id`=".$_GET['page'];
    $result 		= mysql_query($query);
    $info 			= mysql_fetch_array($result);
    $navbar			= $info['display'];
    
    $query 			= "SELECT * FROM `pages` WHERE `navId`=".$_GET['page'];
    $result 		= mysql_query($query);
    $info 			= mysql_fetch_array($result);
    $title 			= $info['title'];
    
    $query 			= "SELECT * FROM `pgContent` WHERE `navId`=".$_GET['page'];
    $result 		= mysql_query($query);
    $info 			= mysql_fetch_array($result);
    $top 			= $info['topBar'];
    $content		= $info['content'];
    
    $body 			='
    
    			<form name="create" method="post" action="php/doEditPage.php?id='.$_GET['page'].'">
    			<div class="label">Page Title:</div> <input type="text" name="title" class="field" value="'.$title.'"/> 
    			<div class="label">Nav Text:</div> <input type="text" name="display" class="field" value="'.$navbar.'"/> 
    			<div class="label">Top Bar:</div> <input type="text" name="topbar" class="field" value="'.$top.'"/> 
    			<div class="label">Content: tags: [<br /> <a> <img> <i> <b> <u>]</div>
    			<textarea rows="15" cols="52" name="content" class="lgfield">'.$content.'</textarea> <br />
    			<input type="submit" value="Edit"  class="button"/>
    			</form>
    
    		';
    
    $page->setContent($body);
    echo $page->content;
    
    ?>

  11. Oh, my, $page is constructed about 3 includes up, above the inclusion of this file. setContent just sets a variable to the value passed to it.

     

    Here is the Page class:

     

    <?php
    
    include 'config.php';
    
    class Page{
    
    function Page(){
    
    	if(isset($_GET['id'])){
    
    		$this->id			= $_GET['id'];
    
    	}
    	else{
    
    		$this->id			= 0;
    
    	}
    
    	if(isset($_GET['option'])){
    
    		$this->option		= $_GET['option'];
    
    	}
    	else{
    
    		$this->option		= 0;
    
    	}
    
    	//pre-initialize append-only variables
    	$this->tab_list		= "";
    	$this->options		= "";
    
    }
    
    function tabs(){ //generates the tabs at the top of the box
    
    	$tab_name				= array('Pages',
    									'Staff',
    									'Profile',
    									);
    
    	$tab_loc				= array('index.php?id=0&option=0',
    									'index.php?id=1&option=0',
    									'index.php?id=2&option=0',
    									);
    
    	for($size = 0; $size < count($tab_loc); $size++){
    
    		if($this->id == $size){
    
    			$this->tab_list		.= '<div class="visit_tab_outer">
    										<div class="visit_tab_inner">
    											<a href="'.$tab_loc[$size].'">'.$tab_name[$size].'</a>
    										</div>
    									</div>';
    			continue;
    
    		}
    
    		$this->tab_list		.= '<div class="tab_outer">
    								<div class="tab_inner">
    									<a href="'.$tab_loc[$size].'">'.$tab_name[$size].'</a>
    								</div>
    							</div>';
    
    	}
    
    	echo $this->tab_list;
    
    }
    
    function appendOp($path, $name, $params = ""){ //adds an option to the sidebar of the page
    
    	if(!empty($params)){
    
    		$path				.= "?";
    
    	}
    
    	$this->nav			.= '<a href="'.$path.$params.'">'.$name.'</a>';
    
    }
    
    function setContent($content){ //set the content of the main body of the page
    
    	$this->content		= $content;
    
    }
    
    }
    
    ?>
    

     

    $page is constructed as an object of the Page class in the main.php file, which is responsible for the file inclusion logic. Here it is:

     

    <?php
    
    include 'classes.php';
    
    $page			= new Page;
    
    switch($page->id){
    
    case 0:{
    
    	include 'pageOptions.php';
    
    	break;
    
    }
    
    case 1:{
    
    	include 'staffOptions.php';
    
    	break;
    
    }
    
    case 2:{
    
    	include 'profileOptions.php';
    
    	break;
    
    }
    
    }
    
    ?>
    

     

    setContent() is working fine, I'm getting the form it was passed, but the values that are supposed to be in the fields are not there. The problem is with the code I originally posted

  12. I have no Idea why the following code is generating a blank form, but it is.

     

    Here is the code that generates the form:

     

    <?php
    
    include 'config.php';
    mysql_select_db("exembar_site");
    
    $query 			= "SELECT * FROM `navigation` WHERE `id`=".$_GET['page'];
    $result 		= mysql_query($query);
    $info 			= mysql_fetch_array($result);
    $navbar			= $info['display'];
    
    $query 			= "SELECT * FROM `pages` WHERE `id`=".$_GET['page'];
    $result 		= mysql_query($query);
    $info 			= mysql_fetch_array($result);
    $title 			= $info['title'];
    
    $query 			= "SELECT * FROM `pgContent` WHERE `id`=".$_GET['page'];
    $result 		= mysql_query($query);
    $info 			= mysql_fetch_array($result);
    $top 			= $info['topBar'];
    $content		= $info['content'];
    
    $body 			='
    
    			<form name="create" method="post" action="php/doEditPage.php?id='.$_GET['page'].'">
    			<div class="label">Page Title:</div> <input type="text" name="title" class="field" value="'.$title.'"/> 
    			<div class="label">Nav Text:</div> <input type="text" name="display" class="field" value="'.$navbar.'"/> 
    			<div class="label">Top Bar:</div> <input type="text" name="topbar" class="field" value="'.$top.'"/> 
    			<div class="label">Content: tags: [<br /> <a> <img> <i> <b> <u>]</div>
    			<textarea rows="15" cols="52" name="content" class="lgfield">'.$content.'</textarea> <br />
    			<input type="submit" value="Edit"  class="button"/>
    			</form>
    
    		';
    
    $page->setContent($body);
    
    ?>

     

    I seem to get this result on occasion, but can never figure out where it came from. I thought I had figured it out, the GET indexes were wrong, but that didn't fix it.

     

    Any and all help is appreciated.

  13. I'm getting an undefined offset error in this code, if the OOP is bad, forgive me, it's late, and any ideas on how to make it better would also be appreciated.

     

    The error:

     

    Notice: Undefined offset: 2 in C:\wamp\www\newsite\team\php\classes.php on line 41

     

    Notice: Undefined offset: 2 in C:\wamp\www\newsite\team\php\classes.php on line 41

     

    The code:

    <?php
    
    include 'config.php';
    
    class Page{
    
    function Page(){
    
    	$this->id			= $_GET['id'];
    	//$this->action		= $_GET['action'];
    
    }
    
    function tabs(){
    
    	$tab_loc				= array('index.php?id=0',
    									'index.php?id=1',
    									);
    
    	$tab_name				= array('A Tab',
    									'Another Tab',
    									);
    
    	$tab_list = "";
    
    	for($size = 0; $size <= count($tab_loc); $size++){
    
    		if($this->id == $size){
    
    			$tab_list 			.= '<div class="visit_tab_outer">
    										<div class="visit_tab_inner">
    											<a href="'.$tab_loc[$size].'">'.$tab_name[$size].'</a>
    										</div>
    									</div>';
    			continue;
    
    		}
    
    		$tab_list		.= '<div class="tab_outer">
    								<div class="tab_inner">
    									<a href="'.$tab_loc[$size].'">'.$tab_name[$size].'</a> // line 41
    								</div>
    							</div>';
    
    	}
    
    	echo $tab_list;
    
    }
    
    }
    
    ?>
    

     

    Thanks for all of your help. :)

     

  14. how else do i use it? here is the code where it is used:

     

    <?php
    
    session_start();
    if(!isset($_SESSION['id'])){
    header("location:login.php");
    }
    
    include 'config.php';
    include 'functions.php';
    
    mysql_select_db('exembar_site');
    
    $id			= $_SESSION['id'];
    $sql			= "SELECT * FROM `permissions` WHERE `staffId`='{$id}'";
    $result			= mysql_query($sql);
    $info			= mysql_fetch_array($result);
    $pages 			= $info['pages'];
    
    if($pages == 0){
    header("location:{$root}/index.php");
    }
    
    $title			= $_POST['title'];
    $display 		= $_POST['display'];
    $top 			= $_POST['topbar'];
    $content 		= $_POST['content'];
    $id 			= $_GET['id'];
    
    //sanitize everything
    $title 			= sanitize($title);
    $display 		= sanitize($display);
    $top 			= sanitize($top);
    $content 		= sanitize($content);
    
    $content                = nl2br($content);
    
    $sql 			= "UPDATE `navigation` SET `display`='{$display}' WHERE id='{$id}'";
    mysql_query($sql) or die(mysql_error());
    
    $sql 			= "UPDATE `pages` SET `title`='{$title}' WHERE `navId`='{$id}'";
    mysql_query($sql) or die(mysql_error());
    
    $sql 			= "UPDATE `pgContent` SET `topBar`='{$top}', `content`='{$content}' WHERE `navId`='{$id}'";
    mysql_query($sql) or die(mysql_error());
    
    header("location:{$root}");
    
    ?>
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.