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

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

Post Reply
ding chavez
Forum Newbie
Posts: 6
Joined: Wed Aug 28, 2002 1:07 am
Location: Sacramento, Ca

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

Post 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>
Last edited by ding chavez on Wed Aug 28, 2002 9:30 am, edited 3 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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.
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post 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
ding chavez
Forum Newbie
Posts: 6
Joined: Wed Aug 28, 2002 1:07 am
Location: Sacramento, Ca

nope

Post by ding chavez »

nope that wasnt it.... i cant figure it out!!!!! anyother suggestions?
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Can't see any other cooding error.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Is the whole page not showing up? If so does a file containing

Code: Select all

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

Mac
sunderwind
Forum Newbie
Posts: 9
Joined: Thu Aug 29, 2002 4:24 am
Location: Irving, TX
Contact:

Post 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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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
ding chavez
Forum Newbie
Posts: 6
Joined: Wed Aug 28, 2002 1:07 am
Location: Sacramento, Ca

Thanks

Post 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!
ding chavez
Forum Newbie
Posts: 6
Joined: Wed Aug 28, 2002 1:07 am
Location: Sacramento, Ca

Post 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>
ding chavez
Forum Newbie
Posts: 6
Joined: Wed Aug 28, 2002 1:07 am
Location: Sacramento, Ca

Post by ding chavez »

i figured it out... im dumb...
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

i'm dumb....
:?: I wouldn't say that.

So what was it?
Post Reply