Page 1 of 2
strange ubrupt end in my code
Posted: Mon Sep 01, 2008 4:08 pm
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
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 4:21 pm
by onion2k
What's that </div> doing in there?
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 4:27 pm
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.
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 5:06 pm
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
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 5:08 pm
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.
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 5:25 pm
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?
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 5:26 pm
by Alphamonkey
it IS getting to my query
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
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 5:29 pm
by jayshields
Paste what your browsers "View Source" looks like.
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 6:03 pm
by califdon
I don't see the
in your latest listing.
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 6:43 pm
by Alphamonkey
califdon wrote:I don't see the
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

Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 7:46 pm
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?
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 7:48 pm
by Alphamonkey
two rows is the correct amount
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 8:10 pm
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.
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 8:15 pm
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
Re: strange ubrupt end in my code
Posted: Mon Sep 01, 2008 8:26 pm
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.