Page 1 of 1

whats wrong with this code.... i cant figure it out...

Posted: Wed Aug 28, 2002 1:07 am
by ding chavez
well lets see.... i wrote this for a news program that im making, i dont know y it isnt working...im not getting error messages, its just not showing up!


plz help


Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#5272A0"><center>

  <p><font color="#FFFFFF" size="6" face="Geneva, Arial, Helvetica, san-serif"><strong>View 
    News</strong></font></p>
	
	<?php
	
	
$db = mysql_connect("localhost","dingdesign","mypassword");
mysql_select_db("dingdesign",$db);
$result = mysql_query("SELECT * FROM news ORDER BY id DESC",$db);
$result2 = mysql_query("SELECT * FROM config",$db);
$num=0;

echo "<table width='75%' height='150' border='0'>\n";
echo "<td width='80%' height='21'>News</font></strong></td>\n";
echo "<td width='20%'>News</td>\n";

while($num<mysql_fetch_row($result)) &#123;	
 
    printf("<tr bgcolor='%s'><td> <strong><font color='%s' face='Geneva, Arial, Helvetica, san-serif'>%s</font></strong></td><td> <strong><font color='%s' face='Geneva, Arial, Helvetica, san-serif'>%s</font></strong></td></tr><tr valign='top' bgcolor='%s'><td colspan='2'><font color='%s' face='Arial, Helvetica, sans-serif'>%s</font></td></tr>",mysql_result($result2,0,"barcolor"),mysql_result($result2,0,"btcolor"),mysql_result($result,$num,"subject");,mysql_result($result2,0,"btcolor"),mysql_result($result,$num,"username"),mysql_result($result2,0,"bodycolor"),mysql_result($result2,0,"mtcolor"),mysql_result($result,$num,"message"));
	
	
	$num=$num+1;
	  &#125;
echo "</table>\n"


?>
</center></body>
</html>

Posted: Wed Aug 28, 2002 1:45 am
by twigletmac
Hi ding, welcome to PHP Developer's network. I note you only signed up today so you obviously haven't had a chance to read much of what's going on here. Basically there are a couple things that you can do to make it easier for us to help you and to not bring one of the moderators down on your head:
  1. Don't cross-post, pick the forum that is most appropriate to your question and post there (I deleted the other two posts), this makes it easier for you to follow the answers and stops everyone getting confused about what's already been offered as a solution;
  2. Tell us what's wrong, give the error messages (if any), tell us what's happening/not happening that shouldn't/should be - just posting 'this doesn't work - here's my code' is not very helpful to anyone.
Mac

PS. Putting in your actual password and username in the mysql_connect() bit may not be the best idea either.

Posted: Wed Aug 28, 2002 9:18 am
by gotDNS
I'm a freak on neat code...but i'll try to keep such feeling dormant in my reply...to whatever extent is humanly possible:

As twiglemac said, don't put an actual password there....make a MySQL account like this:

Code: Select all

grant insert,select,update,delete on *.dingdesign to dingdesign@localhost;
Then when you connect to the DB, you only need:

Code: Select all

$db = mysql_connect("localhost", "dingdesign") && mysql_select_db("dingdesign"),$db;
Anyway, the problems with ur code....*reads*..well, that jumble of code..didn't feel like reading...but:

Code: Select all

echo "</table>\n"
near the bottom should be:

Code: Select all

echo "</table>\n";
I'm pretty sure.

Suggestions: Use CSS...and ditch the FONT tag...*gag*

later on, -Brian

nope

Posted: Wed Aug 28, 2002 9:28 am
by ding chavez
nope that wasnt it.... i cant figure it out!!!!! anyother suggestions?

Posted: Wed Aug 28, 2002 10:12 am
by kcomer
Haven't been able to get any error message, or are you just ignoring the posts that epople send you? It would really help.

Keith

Posted: Wed Aug 28, 2002 10:20 am
by volka
errors are not displayed in the browser if display_errors is Off in your php.ini.
You have to read the server's error-log, too

Posted: Wed Aug 28, 2002 4:22 pm
by Takuma
Can't see any other cooding error.

Posted: Thu Aug 29, 2002 2:32 am
by twigletmac
Is the whole page not showing up? If so does a file containing

Code: Select all

<?php phpinfo(); ?>
do anything?

Mac

Posted: Thu Aug 29, 2002 4:24 am
by sunderwind
I'd be willing to bet that you are using Netscape as your browser. Netscape will not display the contents of a table that is not closed properly. Since the error occurs before you close the table, the table never gets closed. You could view the source and you will see the error.

Your error is coming from your printf statement. One of the functions that you are passing into the printf statement ends in );, Get rid of the semi-colon.

Before you do that though look at the page source. Right click. View Source.

I'm not sure if that is your only error. I stopped when I found that one.

If you are not using Netscape then the php.ini is set to not display errors. In that case you will have to look at the log files.

Hope this helps

Posted: Thu Aug 29, 2002 11:57 am
by BDKR
Somebody really needs to write a debugging 101! In addition, instead of just talkin' crap to the guy, give him some ideas as to how to debug it. Otherwise, what's the point in wasting bandwidth :!: :?:

Now Ding, listen up (as if I was John Terrence Kelly), there are two kinds of things that can be wrong with a prog.

* Parse or programatic error. Leaving out a ";" is a good example.
* A logic error.

Now if you don't get any error messages, then it's more than likely a logic issue. That said, start inserting breaks and or echoing data out at certain points in the script or prog. That way you can see if the code is behaving correctly up to a certain point. If so, move on to the next point.

And the thing that someone else brought up about Netscape is very good and true to boot. In that case, eventhough there is nothing on the screen, view the source. It may seem stupid, but it's most likely there. And guess what? At the bottom of the code, a php error message may be there as well.

Later on and hope that helps,
BDKR

Posted: Thu Aug 29, 2002 12:12 pm
by hob_goblin
try putting this right after $result2

Code: Select all

echo mysql_num_rows($result);
echo "<br/>\n";
echo mysql_num_rows($result2);
if it says
0
0
you know the problem

Thanks

Posted: Sun Sep 01, 2002 3:26 pm
by ding chavez
Thank alot. It turns out that you were right sunderwind... it was the semi-colon! I hate when little stupid stuff like that wastes so much time...

Anyway you guys all helped alot. Thanks!

Posted: Sun Sep 01, 2002 3:31 pm
by ding chavez
one more problem tho....


I deleted all news posts


and when i post once the height of the table cell is very large, then after i add another post it gets a little smaller, and so on, until it just fits the text.

how do i fix this???

is it in the code somewhere

Code: Select all

<html> 
<head> 
<title>Untitled Document</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 

<body bgcolor="#5272A0"><center> 

  <p><font color="#FFFFFF" size="6" face="Geneva, Arial, Helvetica, san-serif"><strong>View 
    News</strong></font></p> 
    
   <?php 
    
    
$db = mysql_connect("localhost","dingdesign","mypassword"); 
mysql_select_db("dingdesign",$db); 
$result = mysql_query("SELECT * FROM news ORDER BY id DESC",$db); 
$result2 = mysql_query("SELECT * FROM config",$db); 
$num=0; 

echo "<table width='75%' height='150' border='0'>\n"; 
echo "<td width='80%' height='21'>News</font></strong></td>\n"; 
echo "<td width='20%'>News</td>\n"; 

while($num<mysql_fetch_row($result)) &#123;    

    printf("<tr bgcolor='%s'><td> <strong><font color='%s' face='Geneva, Arial, Helvetica, san-serif'>%s</font></strong></td><td> <strong><font color='%s' face='Geneva, Arial, Helvetica, san-serif'>%s</font></strong></td></tr><tr valign='top' bgcolor='%s'><td colspan='2'><font color='%s' face='Arial, Helvetica, sans-serif'>%s</font></td></tr>",mysql_result($result2,0,"barcolor"),mysql_result($result2,0,"btcolor"),mysql_result($result,$num,"subject"),mysql_result($result2,0,"btcolor"),mysql_result($result,$num,"username"),mysql_result($result2,0,"bodycolor"),mysql_result($result2,0,"mtcolor"),mysql_result($result,$num,"message")); 
    
    
   $num=$num+1; 
     &#125; 
echo "</table>\n" 


?> 
</center></body> 
</html>

Posted: Sun Sep 01, 2002 3:34 pm
by ding chavez
i figured it out... im dumb...

Posted: Sun Sep 01, 2002 4:42 pm
by BDKR
i'm dumb....
:?: I wouldn't say that.

So what was it?