strange ubrupt end in my code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Alphamonkey
Forum Newbie
Posts: 8
Joined: Mon Sep 01, 2008 4:05 pm

strange ubrupt end in my code

Post by Alphamonkey »

so i have this code, and then after a line......the rest of it doesnt display. i dont recieve any errors or anything. Is it the while loop? its very frustrating and i cant figure out why.

Code: Select all

 
<select name="allparents" id="allparents">           
           <option value=""></option>
  
    <?
      
        $query= "SELECT * FROM $table WHERE layer=1";
        $result = mysql_query($query);
        
        while($row = mysql_fetch_array($result, MYSQL_ASSOC) or die( mysql_error()) )
        {  
            echo "<option value=". $row['title'].">". $row['title']. "</option></div>" ;
        }
 
    ?>                                      
</select>    
anything thats supposed to be visible after that is not
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: strange ubrupt end in my code

Post by onion2k »

What's that </div> doing in there?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: strange ubrupt end in my code

Post by califdon »

Alphamonkey wrote:so i have this code, and then after a line......the rest of it doesnt display. i dont recieve any errors or anything. Is it the while loop? its very frustrating and i cant figure out why.
To see errors, you need to turn on PHP error reporting (for PHP errors) and use MySQL's mysql_error() function. Something like this:

Code: Select all

<?php ini_set("display_errors","2");
ERROR_REPORTING(E_ALL); ?>
  ...
  ...
    $result = mysql_query($query) or die("Query failed!  <br />" . mysql_error() . "<br />". $query);
  ...
You used the "short form" opening tag, which some web servers don't recognize. Always use <$php .

When your script is working properly, remove the error reporting lines for production use, because if an error occurs, it gives useful information to a hacker about your system.
Alphamonkey
Forum Newbie
Posts: 8
Joined: Mon Sep 01, 2008 4:05 pm

Re: strange ubrupt end in my code

Post by Alphamonkey »

onion2k wrote:What's that </div> doing in there?
that was just a little thing i put in there in desperation for fixing the problem
Alphamonkey
Forum Newbie
Posts: 8
Joined: Mon Sep 01, 2008 4:05 pm

Re: strange ubrupt end in my code

Post by Alphamonkey »

califdon wrote:
Alphamonkey wrote:so i have this code, and then after a line......the rest of it doesnt display. i dont recieve any errors or anything. Is it the while loop? its very frustrating and i cant figure out why.
To see errors, you need to turn on PHP error reporting (for PHP errors) and use MySQL's mysql_error() function. Something like this:

Code: Select all

<?php ini_set("display_errors","2");
ERROR_REPORTING(E_ALL); ?>
  ...
  ...
    $result = mysql_query($query) or die("Query failed!  <br />" . mysql_error() . "<br />". $query);
  ...
You used the "short form" opening tag, which some web servers don't recognize. Always use <$php .

When your script is working properly, remove the error reporting lines for production use, because if an error occurs, it gives useful information to a hacker about your system.

i put in the

Code: Select all

<?php ini_set("display_errors","2");
ERROR_REPORTING(E_ALL); ?>
and the

Code: Select all

$result = mysql_query($query) or die("Query failed!  <br />" . mysql_error() . "<br />". $query);
and i see no difference

but....whats very interesting is that if i PURPOSELY change the syntax of the sql query to throw an error.....it doesn't display the error BUT it does in the pages SOURCE file.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: strange ubrupt end in my code

Post by califdon »

Alphamonkey wrote:i put in the

Code: Select all

<?php ini_set("display_errors","2");
ERROR_REPORTING(E_ALL); ?>
and the

Code: Select all

$result = mysql_query($query) or die("Query failed!  <br />" . mysql_error() . "<br />". $query);
and i see no difference

but....whats very interesting is that if i PURPOSELY change the syntax of the sql query to throw an error.....it doesn't display the error BUT it does in the pages SOURCE file.
Hmmm. That sounds like it isn't even getting to your query. What displays in the Source file? Code? Which part?
Alphamonkey
Forum Newbie
Posts: 8
Joined: Mon Sep 01, 2008 4:05 pm

Re: strange ubrupt end in my code

Post by Alphamonkey »

it IS getting to my query :banghead:

Code: Select all

 
<?php
          ini_set("display_errors","2");
             
            
            $query= "SELECT * FROM $table WHERE layer=1";
            $result = mysql_query($query) or die("Query failed!  <br />" . mysql_error() . "<br />". $query);
            while($row = mysql_fetch_array($result, MYSQL_ASSOC) or die( mysql_error()) )
            {  
                echo "<option value=". $row['title'].">". $row['title']. "</option>" ;
                }
        ?>
                                              
    </select> 
    </div>                            
    <input type="submit" />
 
the select box is filled! i just cant see the submit button
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: strange ubrupt end in my code

Post by jayshields »

Paste what your browsers "View Source" looks like.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: strange ubrupt end in my code

Post by califdon »

I don't see the

Code: Select all

ERROR_REPORTING(E_ALL);
in your latest listing.
Alphamonkey
Forum Newbie
Posts: 8
Joined: Mon Sep 01, 2008 4:05 pm

Re: strange ubrupt end in my code

Post by Alphamonkey »

califdon wrote:I don't see the

Code: Select all

ERROR_REPORTING(E_ALL);
in your latest listing.
thats because it makes no difference in this case, but ill add it 2 show you

ok heres the code

Code: Select all

<?php echo " <span style='color:red'>$welcome</span> </div>"?>
   <h1><?php echo ucwords($color) ?> Menu: Add Element</h1>
  <form name="addmenuelement" id="addmenuelement" method="post" action="<?php echo $action ?>">
                 
  Title:
   <input type="text" name="title" id="title" align="left"> <div />
   
  Link:
    <input type="text" name="link" id="link" align="left">      <div />   
   
  Does this have a Parent?:
    <input type="checkbox" name="hasparent" id="hasparent">   <div />  
   
  If So......Parent Name: 
    <select name="allparents" id="allparents">           
        <option value=""></option>
        
          <?php
          ini_set("display_errors","2");
          ERROR_REPORTING(E_ALL);   
            
            $query= "SELECT * FROM $table WHERE layer=1";
            $result = mysql_query($query) or die("Query failed!  <br />" . mysql_error() . "<br />". $query);
            while($row = mysql_fetch_array($result, MYSQL_ASSOC) or die( mysql_error()) )
            {  
                echo "<option value=". $row['title'].">". $row['title']. "</option>" ;
                }
        ?>
                                              
    </select> 
    </div>                            
    <input type="submit" />
    
  </form>                    
heres the source

Code: Select all

       
 
        
   
    <span style='color:red'></span> </div>   <h1>Orange Menu: Add Element</h1>
  <form name="addmenuelement" id="addmenuelement" method="post" action="addmenuscript.php?c=orange">
                 
  Title:
   <input type="text" name="title" id="title" align="left"> <div />
   
  Link:
    <input type="text" name="link" id="link" align="left">      <div />   
   
  Does this have a Parent?:
    <input type="checkbox" name="hasparent" id="hasparent">   <div />  
   
  If So......Parent Name: 
    <select name="allparents" id="allparents">           
        <option value=""></option>
 
        
          <option value=Home>Home</option><option value=Leagues>Leagues</option>
you can see that the source does not display the submit button :(
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: strange ubrupt end in my code

Post by califdon »

So, it just craps out after 2 rows? I don't see any reason for that, unless (remotely possible) there's a nonprinting character in your script between the end of the while loop and the </select>. You might backspace over everything between, then put in just a linefeed. How many rows should it have returned? Are there more than the 2 rows in the table?
Alphamonkey
Forum Newbie
Posts: 8
Joined: Mon Sep 01, 2008 4:05 pm

Re: strange ubrupt end in my code

Post by Alphamonkey »

two rows is the correct amount
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: strange ubrupt end in my code

Post by califdon »

I'm afraid I don't see what is causing it to halt execution. As onion2k said, you are misusing those <div /> and </div> tags, but I think the browser just ignores them. Still, you should remove them. <div> is an element that always needs a closing </div> tag, so <div /> is just invalid, and the lone </div> without a beginning <div> is meaningless. At the moment, I don't know what else to tell you.
Alphamonkey
Forum Newbie
Posts: 8
Joined: Mon Sep 01, 2008 4:05 pm

Re: strange ubrupt end in my code

Post by Alphamonkey »

ok, ill ask elsewhere. the "<div />" is just for a line break. I've gotten in the habit of using it. I guess i should try and quit that habit
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: strange ubrupt end in my code

Post by califdon »

Alphamonkey wrote:ok, ill ask elsewhere. the "<div />" is just for a line break. I've gotten in the habit of using it. I guess i should try and quit that habit
Definitely YES. A line break is <br />. Don't ever put invalid tags in your code, you might get by with it sometimes, but generally it will break your page.
Post Reply