|
-
May 9th, 2002, 03:51 AM
#1
Thread Starter
PowerPoster
Style tags
The book I'm reading is not helpful with this. I understand that html style tags must be surrounded with double quotes. When I do that, my PHP code doesn't work. When I take the double_quotes away, the formatting is wrong. What am I doing wrong? I've tried these three ways:
$UserName, $Date and $Comments are being pulled from a mySQL database. That part works.
Replace double-quotes with single quotes. Really screwed up output doing this.
print("<table border=‘0’ cellpadding=‘0’ cellspacing=‘0’ style=‘border-collapse: collapse’ width=‘100%’ id=‘AutoNumber1’>
<tr>
<td width=‘100%’ colspan=‘2’ bgcolor=‘#3366CC’ style=‘border-style: solid; border-width: 1; padding: 4’ bordercolor=‘#000000’ bordercolorlight=‘#000000’ bordercolordark=‘#000000’> </td>
</tr>
<tr>
<td width=‘50%’ style=‘border:1px solid #000000; padding:4; ‘ bgcolor=‘#FF6666’ bordercolorlight=‘#000000’ bordercolordark=‘#000000’>
<p style=‘text-align: left’><b><font face=‘Arial’>$UserName</font></b></td>
<td width=‘50%’ style=‘border:1px solid #000000; padding: 4’ bgcolor=‘#FF6666’ bordercolorlight=‘#000000’ bordercolordark=‘#000000’>
<p style=‘text-align: right’><b><font face=‘Arial’>$Date</font></b></td>
</tr>
<tr>
<td width=‘100%’ colspan=‘2’ bgcolor=‘#FFFFFF’ style=‘border:1px solid #000000; padding:4; ‘ bordercolorlight=‘#000000’ bordercolordark=‘#000000’>
<font face=‘Arial’ size=‘2’>$Comments</font></td>
</tr>
<tr>
<td width=‘100%’ bgcolor=‘#3366CC’ colspan=‘2’ style=‘border:1px solid #000000; padding:4; ‘ bordercolorlight=‘#000000’ bordercolordark=‘#000000’> </td>
</tr>
</table>");
Retaining the double quotes as follows results in no PHP output at all:
print("<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber1">
<tr>
<td width="100%" colspan="2" bgcolor="#3366CC" style="border-style: solid; border-width: 1; padding: 4" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#000000"> </td>
</tr>
<tr>
<td width="50%" style="border:1px solid #000000; padding:4; " bgcolor="#FF6666" bordercolorlight="#000000" bordercolordark="#000000">
<p style="text-align: left"><b><font face="Arial">$UserName</font></b></td>
<td width="50%" style="border:1px solid #000000; padding: 4" bgcolor="#FF6666" bordercolorlight="#000000" bordercolordark="#000000">
<p style="text-align: right"><b><font face="Arial">$Date</font></b></td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#FFFFFF" style="border:1px solid #000000; padding:4; " bordercolorlight="#000000" bordercolordark="#000000">
<font face="Arial" size="2">$Comments</font></td>
</tr>
<tr>
<td width="100%" bgcolor="#3366CC" colspan="2" style="border:1px solid #000000; padding:4; " bordercolorlight="#000000" bordercolordark="#000000"> </td>
</tr>
</table>");
removing the quotes altogether gets me closest, but some things are wrong. For example, the date should be right aligned, but it ends up being left aligned:
print("<table border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse width=100% id=AutoNumber1>
<tr>
<td width=100% colspan=2 bgcolor=#3366CC style=border-style: solid; border-width: 1; padding: 4 bordercolor=#000000 bordercolorlight=#000000 bordercolordark=#000000> </td>
</tr>
<tr>
<td width=50% style=border:1px solid #000000; padding:4; bgcolor=#FF6666 bordercolorlight=#000000 bordercolordark=#000000>
<p style=text-align: left><b><font face=Arial>$UserName</font></b></td>
<td width=50% style=border:1px solid #000000; padding: 4 bgcolor=#FF6666 bordercolorlight=#000000 bordercolordark=#000000>
<p style=text-align: right><b><font face=Arial>$Date</font></b></td>
</tr>
<tr>
<td width=100% colspan=2 bgcolor=#FFFFFF style=border:1px solid #000000; padding:4; bordercolorlight=#000000 bordercolordark=#000000>
<font face=Arial size=2>$Comments</font></td>
</tr>
<tr>
<td width=100% bgcolor=#3366CC colspan=2 style=border:1px solid #000000; padding:4; bordercolorlight=#000000 bordercolordark=#000000> </td>
</tr>
</table>");
-
May 9th, 2002, 08:04 AM
#2
Addicted Member
Stick a \ before the double quotes:
echo "This \"will\" work<br>";
What is the answer to this question?
-
May 9th, 2002, 10:33 AM
#3
Thread Starter
PowerPoster
so I just paste it into Word then replace all " with \". Outstanding. Thank you Mr. Wilson.
-
May 9th, 2002, 12:04 PM
#4
Thread Starter
PowerPoster
OK, I'm just not getting this.
This is how it's supposed to look:
http://www.paulkjohnson.com/modelbuilding/test.htm
This is the exact same code converted to PHP with the quotes replaced with \"
http://www.paulkjohnson.com/modelbuilding/test.php
-
May 9th, 2002, 01:07 PM
#5
those were 2 totally different pages. what is the code you are trying to get to work?
-
May 9th, 2002, 01:11 PM
#6
Thread Starter
PowerPoster
They're supposed to be the same. I took the html from the "normal" page, put it in word, replaced the double quotes with backslash + double quote
" = \"
and that's what happened.
Before:
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber1">
<tr>
<td width="100%" colspan="2" bgcolor="#3366CC" style="border-style: solid; border-width: 1; padding: 4" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#000000"> </td>
</tr>
<tr>
<td width="50%" style="border:1px solid #000000; padding:4; " bgcolor="#FF6666" bordercolorlight="#000000" bordercolordark="#000000">
<p style="text-align: left"><b><font face="Arial">User name</font></b></td>
<td width="50%" style="border:1px solid #000000; padding: 4" bgcolor="#FF6666" bordercolorlight="#000000" bordercolordark="#000000">
<p style="text-align: right"><b><font face="Arial">Date</font></b></td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#FFFFFF" style="border:1px solid #000000; padding:4; " bordercolorlight="#000000" bordercolordark="#000000">
<font face="Arial" size="2">Comments</font></td>
</tr>
<tr>
<td width="100%" bgcolor="#3366CC" colspan="2" style="border:1px solid #000000; padding:4; " bordercolorlight="#000000" bordercolordark="#000000"> </td>
</tr>
</table>
After:
print("<table border=\”0\” cellpadding=\”0\” cellspacing=\”0\” style=\”border-collapse: collapse\” width=\”100%\” id=\”AutoNumber1\”>
<tr>
<td width=\”100%\” colspan=\”2\” bgcolor=\”#3366CC\” style=\”border-style: solid; border-width: 1; padding: 4\” bordercolor=\”#000000\” bordercolorlight=\”#000000\” bordercolordark=\”#000000\”> </td>
</tr>
<tr>
<td width=\”50%\” style=\”border:1px solid #000000; padding:4; \” bgcolor=\”#FF6666\” bordercolorlight=\”#000000\” bordercolordark=\”#000000\”>
<p style=\”text-align: left\”><b><font face=\”Arial\”>$UserName</font></b></td>
<td width=\”50%\” style=\”border:1px solid #000000; padding: 4\” bgcolor=\”#FF6666\” bordercolorlight=\”#000000\” bordercolordark=\”#000000\”>
<p style=\”text-align: right\”><b><font face=\”Arial\”>$Date</font></b></td>
</tr>
<tr>
<td width=\”100%\” colspan=\”2\” bgcolor=\”#FFFFFF\” style=\”border:1px solid #000000; padding:4; \” bordercolorlight=\”#000000\” bordercolordark=\”#000000\”>
<font face=\”Arial\” size=\”2\”>$Comments</font></td>
</tr>
<tr>
<td width=\”100%\” bgcolor=\”#3366CC\” colspan=\”2\” style=\”border:1px solid #000000; padding:4; \” bordercolorlight=\”#000000\” bordercolordark=\”#000000\”> </td>
</tr>
</table>");
-
May 9th, 2002, 01:16 PM
#7
it looks ok to me. but if you are going to put all that into one print commend then just take the print out and make it regular html.
-
May 9th, 2002, 01:22 PM
#8
Thread Starter
PowerPoster
Because I don't know html, php or mysql. 
Really, I've always used front page. But I'm trying to learn php and mySQL which is making me learn html too. So I'm taking on three things at once.
The reason I'm putting it in the php is because of the fields from the database. I don't know another way to do it. Basically, I just took the example from the book and converted it as well as I could. I'm really lost here and the tutorials I've come across don't help much.
The book (php4) just had standard borders with no styles at all. So it didn't help. But it showed me how to connect to the database and such.
Can you show me how to split it up better please? I'm assuming I can use the print command to just put the fields in the middle of the html, but I've tried that too with resounding failure.
-
May 9th, 2002, 01:30 PM
#9
Try this one first. somethnig looked funny about your "
Code:
echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"100%\" id=\"AutoNumber1\">
<tr>
<td width=\"100%\" colspan=\"2\" bgcolor=\"#3366CC\" style=\"border-style: solid; border-width: 1; padding: 4\" bordercolor=\"#000000\" bordercolorlight=\"#000000\" bordercolordark=\"#000000\"> </td>
</tr>
<tr>
<td width=\"50%\" style=\"border:1px solid #000000; padding:4; \" bgcolor=\"#FF6666\" bordercolorlight=\"#000000\" bordercolordark=\"#000000\">
<p style=\"text-align: left\"><b><font face=\"Arial\">$UserName</font></b></td>
<td width=\"50%\" style=\"border:1px solid #000000; padding: 4\" bgcolor=\"#FF6666\" bordercolorlight=\"#000000\" bordercolordark=\"#000000\">
<p style=\"text-align: right\"><b><font face=\"Arial\">$Date</font></b></td>
</tr>
<tr>
<td width=\"100%\" colspan=\"2\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #000000; padding:4; \" bordercolorlight=\"#000000\" bordercolordark=\"#000000\">
<font face=\"Arial\" size=\"2\">$Comments</font></td>
</tr>
<tr>
<td width=\"100%\" bgcolor=\"#3366CC\" colspan=\"2\" style=\"border:1px solid #000000; padding:4; \" bordercolorlight=\"#000000\" bordercolordark=\"#000000\"> </td>
</tr>
</table>";
-
May 9th, 2002, 01:36 PM
#10
Thread Starter
PowerPoster
OK, that is much better. The first blue row in the table is missing now, but the rest is the way it's supposed to be. Can you give me the cliff's notes on what you did? Was it just a change to echo or is there more to it? I'll look at the code and see if I can tell the difference, but since I don't know html, I doubt I'll understand it.
-
May 9th, 2002, 01:36 PM
#11
Thread Starter
PowerPoster
Oh yeah... Thanks
-
May 9th, 2002, 01:39 PM
#12
well I did change teh print to echo but that didn't make a difference. they will do the same job. all I did was change your ” to "
what did you use? they don't look like quotes, that is all I did.
your welcome and have fun.
-
May 9th, 2002, 01:43 PM
#13
Thread Starter
PowerPoster
I used Word. Maybe it replaced them with "Smart quotes." OK, that's probably the problem. I'll put it in another editor next time. Much faster than manually going through and changing it.
Thanks again.
-
May 9th, 2002, 01:49 PM
#14
Thread Starter
PowerPoster
Just for S and G's, I changed it back to print and it works fine. It was the quotes. The blue row was collapsing because there is no text in it. I'm sure there's a way to handle that in HTML, but until I figure out what it is, I just put a space character in it and it's doing what it's supposed to now.
Thanks.
Stay tuned... more questions will be coming soon.
-
May 9th, 2002, 01:51 PM
#15
good job.
that is correct by the way. if your table cell has nothing in it it will not render correctly. always have at least something in it like &nbsp; is all it needs.
-
May 9th, 2002, 02:01 PM
#16
Thread Starter
PowerPoster
ok, this is what I've got.
The next thing I'm going to be asking about is creating an input form that a user can use to flame my site. 
I'll go ahead and construct the form and do what I can and if I have problems I'll start a new thread. My book talks about it a bit. My main concern is that it mentioned that people can put html code into the fields that will execute, possibly maliciously, when the page the fields from the database get displayed.
Of course I don't want that to happen, but the first thing I want to do is get the form working at all. Then I'll try to figure out the security. It did say something about how to prevent it, but I didn't really understand what they were talking about.
here's where it stands now.
http://www.paulkjohnson.com/modelbuilding/test.php
Thanks again for all the help.
-
May 9th, 2002, 02:08 PM
#17
Thread Starter
PowerPoster
Sorry, scoutt. You're in the guest book now. See what you get for helping? Go back and refresh the page.
-
May 9th, 2002, 02:10 PM
#18
PowerPoster
there are a number of built in functions you can use to remove malicious user input
check out strip_tags(), htmlspecialchars(), addslashes(), stripslashes()
-
May 9th, 2002, 02:13 PM
#19
Thread Starter
PowerPoster
oh yeah... gotta add chrisjk too 
If you guys don't like what I'm doing in your name, just say so and I'll remove it. It's just for learning purposes. If I actually do implement it, I'm going to clear out the database before I do.
Thanks again for your help.
-
May 9th, 2002, 02:22 PM
#20
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|